diff --git a/resources/js/blocks/molliePaymentMethod.js b/resources/js/blocks/molliePaymentMethod.js index 3c09149f..e8f79e60 100644 --- a/resources/js/blocks/molliePaymentMethod.js +++ b/resources/js/blocks/molliePaymentMethod.js @@ -1,5 +1,10 @@ let cachedAvailableGateways = {}; +function formatPriceLikeWc(price) { + // todo add thousandSeparator + return wcSettings.currency.priceFormat.replace('%1$s', wcSettings.currency.symbol).replace('%2$s',price.toFixed(wcSettings.currency.precision).replace('.', wcSettings.currency.decimalSeparator)); +} + function loadCachedAvailableGateways() { const storedData = localStorage.getItem('cachedAvailableGateways'); if (storedData) { @@ -93,24 +98,21 @@ const MollieComponent = (props) => { const billingPhone = document.getElementById('billing-phone'); return billingPhone || shippingPhone; } - function updateTotalLabel(newTotal, currency) { - let feeText = newTotal + " " + currency - let totalSpan = "" + feeText + "" + function updateTotalLabel(newTotal) { + let totalSpan = "" + formatPriceLikeWc(newTotal) + "" let total = jQuery('.wc-block-components-totals-footer-item .wc-block-formatted-money-amount:first') total.replaceWith(totalSpan) } - function updateTaxesLabel(newTotal, currency) { - let feeText = newTotal + " " + currency - - let totalSpan = "" + feeText + "" + function updateTaxesLabel(newTotal) { + let totalSpan = "" + formatPriceLikeWc(newTotal) + "" let total = jQuery('div.wp-block-woocommerce-checkout-order-summary-taxes-block.wc-block-components-totals-wrapper > div > span.wc-block-formatted-money-amount.wc-block-components-formatted-money-amount.wc-block-components-totals-item__value:first') total.replaceWith(totalSpan) } function hideFee(fee, response) { fee?.hide() - updateTotalLabel(response.data.newTotal.toFixed(2).replace('.', ','), response.data.currency); - updateTaxesLabel(response.data.totalTax.toFixed(2).replace('.', ','), response.data.currency); + updateTotalLabel(response.data.newTotal); + updateTaxesLabel(response.data.totalTax); } function feeMarkup(response) { @@ -119,7 +121,7 @@ const MollieComponent = (props) => { + response.data.name + "" + "" - + response.data.amount.toFixed(2).replace('.', ',') + " " + response.data.currency + + formatPriceLikeWc(response.data.amount) + "" + "