Skip to main content

[Solved] Currency format

Hey, How can I change this: 9.000,00 UAH

To this: 9 000 грн.

1.00

Oh my, please give a code snippet for that or whatever.

Solved by biiig snippet

Maaz Shakir

Volodymyr Pimienov Can you share the snippet thanks in advance

Maaz Shakir // 1. ОЧИЩЕННЯ ЦІН ДЛЯ ВСІХ СТОРІНОК (JS)
add_action('wp_footer', function() {
?>
(function() {
function cleanFluentCartPrices() {
// Звичайні текстові елементи (Магазин, картки, кошик, чекаут, сторінка товару)
const priceElements = document.querySelectorAll(
'.fct_line_item_total, [data-fluent-cart-checkout-estimated-total], .fct_summary_value, .fct_item_payment_info span, ' +
'.fct-item-price span, .fct-item-price, .fct_price_filter_amount, .fct-min-price, .fct-max-price, ' +
'[data-fluent-cart-cart-list-item-total-price], [data-fluent-cart-cart-list-item-price], [data-fluent-cart-cart-total-price], .fct-cart-item-total span'
);

        priceElements.forEach(el => {
            let text = el.textContent;

            if ((text.includes('UAH') || text.includes('₴')) && !text.includes('грн')) {
                if (text.trim() === '₴') {
                    el.textContent = '';
                    return;
                }

                let cleanText = text.replace(/UAH/g, '').replace(/₴/g, '').trim();
                cleanText = cleanText.replace(/([.,]00)\s*$/, '');
                let digitsOnly = cleanText.replace(/[.,\s]/g, '');

                if (digitsOnly && !isNaN(digitsOnly)) {
                    let formattedNumber = Number(digitsOnly).toLocaleString('ru-RU').replace(/\u00A0/g, ' ');

                    if (el.closest('.fct_item_payment_info')) {
                        el.textContent = ' ' + formattedNumber + ' грн / міс. ';
                    } else {
                        el.textContent = formattedNumber + ' грн';
                    }
                }
            }
        });

        // Інпути у фільтрі ціни ліворуч
        const priceInputs = document.querySelectorAll('#price-range-from, #price-range-to');
        priceInputs.forEach(input => {
            let val = input.value;
            if (val && !input.dataset.cleaned) {
                let cleanVal = val.replace(/[.,]00$/, '').replace(/[.,\s]/g, '');
                if (!isNaN(cleanVal) && cleanVal !== '') {
                    input.value = Number(cleanVal).toLocaleString('ru-RU').replace(/\u00A0/g, ' ');
                    input.dataset.cleaned = 'true';
                }
            }
        });
    }

    document.addEventListener('DOMContentLoaded', cleanFluentCartPrices);
    window.addEventListener('load', cleanFluentCartPrices);

    const observer = new MutationObserver((mutations) => {
        cleanFluentCartPrices();
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();
</script>
<?php

}, 999);

// 2. СТИЛІЗАЦІЯ ВСІХ КНОПОК "BUY NOW" ТА КОРИГУВАННЯ ФІЛЬТРА (CSS)
add_action('wp_head', function() {
?>
/ Робимо ВСІ кнопки Buy Now білими з чорною рамкою 1px та чорним текстом /
.fct-product-card .fct-product-view-button,
.fct-product-buttons-wrap .fluent-cart-direct-checkout-button,
.fct_product_card_actions .fct_btn_buy_now,
button.fct_btn_buy_now,
a.fct_btn_buy_now,
a.fluent-cart-direct-checkout-button {
background-color: #ffffff !important;
color: #000000 !important;
border: 1px solid #000000 !important;
text-align: center !important;
display: inline-flex !important;
align-items: center !important;
justify-content: center !important;
transition: all 0.2s ease-in-out !important;
text-transform: none !important;
font-weight: 500 !important;
}

/* Ефект при наведенні для всіх типів кнопок Buy Now */
.fct-product-card .fct-product-view-button:hover,
.fct-product-buttons-wrap .fluent-cart-direct-checkout-button:hover,
.fct_product_card_actions .fct_btn_buy_now:hover,
a.fluent-cart-direct-checkout-button:hover {
    background-color: #f5f5f5 !important;
    color: #000000 !important;
    opacity: 1 !important;
    border-color: #000000 !important;
}

/* Прибираємо наліплені значки валют біля інпутів у фільтрі ціни */
.fct-shop-price-range .fct-shop-currency-sign {
    display: none !important;
}

.fct-shop-price-range-wrap {
    gap: 10px !important;
}
</style>
<?php

}, 999);