Home / Admin / Hiding the Currency Symbol in WPForms Total Field
Duplicate Snippet

Embed Snippet on Your Site

Hiding the Currency Symbol in WPForms Total Field

This code snippet removes the following currency symbols from the Total field: £, $, €.

<10
Code Preview
php
<?php
function wpf_remove_currency_symbol() {
    ?>
    <script type="text/javascript">
        (function($){
            $(document).ready(function(){
                const targetNode = document.querySelector('.wpforms-payment-total');
                if (!targetNode) return;
                const config = { childList: true, subtree: true, characterData: true };
                
                const callback = function(mutationsList, observer) {
                    for(let mutation of mutationsList) {
                        if (mutation.type === 'childList' || mutation.type === 'characterData') {
                            targetNode.textContent = targetNode.textContent.replace(/[£$€]/g, '');
                        }
                    }
                };
                const observer = new MutationObserver(callback);
                observer.observe(targetNode, config);
                // Initial removal of currency symbol
                targetNode.textContent = targetNode.textContent.replace(/[£$€]/g, '');
            });
        })(jQuery);
    </script>
    <?php
}
add_action('wpforms_wp_footer', 'wpf_remove_currency_symbol', 30);

Comments

Add a Comment