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

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

  1. hi! I know it is a year later, but, perhaps you can help?
    I do not know code, but am creating a woocommerce website. Have added a “go back” button with your code ( huge thanks!) but it is larger than the button it sits next to. No idea how to change that. Would you have any easy tips?
    here is the button https://cookiespot.ie/product/hearts-and-flowers/
    I’d appreciate any help.
    Have a great day!

Share your thoughts

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