Search code examples
phpwordpresswoocommercecarthook-woocommerce

Avoid proceed-to-checkout-button text refreshing to default text in WooCommerce cart page


In WooCommerce, in my Storefront child theme, I edited the code in proceed-to-checkout-button.php to change the wording from "Proceed to checkout" to "Checkout":

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
?>

<a href="<?php echo esc_url( wc_get_checkout_url() ); ?>" class="checkout-button button wc-forward">
    <?php esc_html_e( 'Checkout', 'woocommerce' ); ?>
</a> 

But when the user changes product quantity in the cart page, then the button text goes back to default "Proceed to checkout".

Is there a filter or where to edit this updated text?


EDIT - Problem Solved

The issue was related to a specific cart option in WooCommerce Better Usability pro plugin where the option "Display text while updating cart automatically" requires to be disabled (unselected).


Solution

  • Instead of overriding proceed-to-checkout-button.php file, should use the following instead:

    remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
    add_action( 'woocommerce_proceed_to_checkout', 'custom_button_proceed_to_checkout', 20 );
    function custom_button_proceed_to_checkout() {
        echo '<a href="'.esc_url(wc_get_checkout_url()).'" class="checkout-button button alt wc-forward">' .
        __("Checkout", "woocommerce") . '</a>';
    }
    

    Code goes in functions.php file of your active child theme (or active theme). Tested and works on last WooCommerce version under Storefront theme.

    Now as you have done a lot of customizations in your templates or may be you are using some plugin in cart page for customization, the problem can remains due to those customizations.