Home / Archive / MemberPress: Replace Text in Group Price Box for Classic Tempalate
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Replace Text in Group Price Box for Classic Tempalate

This code snippet is designed to dynamically replace specified text within the MemberPress price box elements.

To replace an existing text on Group price box, replace the following:

"old text" in the code with the current text like '$20 / year'.
"new text" in the code with the text you want, like '$20 / annum'

These changes should be made on the following lines:

priceBox.innerHTML = priceBox.innerHTML.replace('old text', 'new text');

Code Preview
php
<?php
function replace_text_in_price_box() {
    ?>
    <script type="text/javascript">
        document.addEventListener("DOMContentLoaded", function() {
            setTimeout(function() {
                // Select all elements with the class 'mepr-price-box-price'
                var priceBoxes = document.querySelectorAll('.mepr-price-box-price');
                // Iterate through each selected element
                priceBoxes.forEach(function(priceBox) {
                    if (priceBox) {
                        // Replace specific text within the element's HTML
                        priceBox.innerHTML = priceBox.innerHTML.replace('old text', 'new text');
                    }
                });
            }, 1000); // Adjust the timeout as needed
        });
    </script>
    <?php
}
add_action('wp_footer', 'replace_text_in_price_box');

Comments

Add a Comment