Change the text of the customization button when it comes from the cart

Posted 26 days ago by V.I.

Post a topic
Un Answered
V
V.I.

If you use the lightbox and the customer clicks on the product added to the cart to modify it, it should be written on the customization button (which opens the customizer in the lightbox): "Modify customization" to make it more intuitive that they are going to modify the customization already done

0 Votes


3 Comments

Sorted by
O

Olivia posted 17 days ago

Hi V.I. !
It's a great news ! 

I'm not very comfortable with javascript and I always turn to the PHP version of the snippets which I arrange "to my own taste" ;)

Glad you solve it so fast !

Olivia

0 Votes

V

V.I. posted 18 days ago

Thanks a lot Olivia, I managed to implement using the cart_item_key parameter only that the code should modify the fpd-start-customizing-button. So thanks to your idea with the cart_item_key parameter and with the help of chatgpt I managed to create the code below which works perfectly:


function custom_change_button_text_script() {
    ?>
    <script type="text/javascript">
        document.addEventListener('DOMContentLoaded', function() {
            var button = document.getElementById('fpd-start-customizing-button');
            if (button) {
                var urlParams = new URLSearchParams(window.location.search);
                if (urlParams.has('cart_item_key')) {
                    button.textContent = 'Modify customization';
                }
            }
        });
    </script>
    <?php
}

Thank you again :)

1 Votes

O

Olivia posted 18 days ago

Hi V.I.,

I think a quick PHP snippet will do the job :)


I use the woocommerce_product_single_add_to_cart_text filter to modify the button text.

The custom_add_to_cart_text function checks if the URL parameter 'cart_item_key' is present. This parameter is typically added when a customer clicks on 'Edit product' in the cart.

If the parameter is present, the button text changes to 'Modify customization'. (You can modify this text according to your preferences.)

If the parameter is not present, we return the original button text


Here's the snippet to add to your functions.php file. Let me know if you need help implementing this !



add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_text', 10, 2 );

function custom_add_to_cart_text( $button_text, $product ) {

    if ( isset( $_GET['cart_item_key'] ) ) {

        return __( 'Modify customization', 'woocommerce' ); // Replace by your own text 

    }

    return $button_text;

}


0 Votes

Login or Sign up to post a comment