user6573193 user6573193 -4 years ago 108
PHP Question

Back to cart button on checkout page

Is there any solution to display a "back to shopping cart" button on the WooCommerce checkout page?

Actually there is only a complete order button, but we need a back button, if a user want to correct his order.


Answer Source

Yes it's possible to display a custom notice with a "Back to Cart" button on checkout page. Here is that custom hooked function in woocommerce_before_checkout_form action hook:

add_action( 'woocommerce_before_checkout_form', 'return_to_cart_notice_button' );
function return_to_cart_notice_button(){

    // HERE Type your displayed message and text button
    $message = __('Go back to the Cart page', 'woocommerce');
    $button_text = __('Back to Cart', 'woocommerce');

    $cart_link = WC()->cart->get_cart_url();

    wc_add_notice( '<a href="' . $cart_link . '" class="button wc-forward">' . $button_text . '</a>' . $message, 'notice' );

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

The code is tested and works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download