How to add a go back button on your WooCommerce single product pages.

You can use the following code snippet to add a “Go back” button inline to the “Add to cart” button on all your single product pages in WooCommerce. This is the output:

add_action( 'woocommerce_after_add_to_cart_button', 'my_function_sample', 10 );
function my_function_sample() {
  global $product;
  echo ' <button type="button" onclick="history.back();"> Go back </button> '; 
}

This code can be added following the instructions here:

How to add custom code to your WooCommerce/WordPress site the right way

Have any feedback? Be sure to let me know here: Contact me

Share your thoughts

Your email address will not be published. Required fields are marked *