Title: Back button / Return button
Last modified: October 9, 2017

---

# Back button / Return button

 *  Resolved [ethink1](https://wordpress.org/support/users/ethink1/)
 * (@ethink1)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/back-button-return-button/)
 * Hello!
    I would like to add a back button in single product pages to return to
   shop page. Also, I would like to add another one in purchase process to go back
   through cart page, checkout, etc. Any ideas to include that? I was looking for
   and I didn’t found anything. Is possible adding code (what, where…)? Or arte 
   there any addon with these funcionalities? Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Oscar Abad Folgueira](https://wordpress.org/support/users/oabadfol/)
 * (@oabadfol)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/back-button-return-button/#post-9570569)
 * Hi [@ethink1](https://wordpress.org/support/users/ethink1/).
 * You can add some code like this in a function:
 * `<button type="button" onclick="history.back();"> Back </button>`
 * And then, call to this function from “add_action” with the hook you prefer.
 * Then, you can add some css for style the back button.
 * Regards.
 *  [Rynald0s](https://wordpress.org/support/users/rynald0s/)
 * (@rynald0s)
 * Automattic Happiness Engineer
 * [8 years, 7 months ago](https://wordpress.org/support/topic/back-button-return-button/#post-9570615)
 * Hi there!
 * > I would like to add a back button in single product pages to return to shop
   > page.
 * You can use the following code to add the “Go back” button on the single product
   page:
 *     ```
       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> '; 
       }
       ```
   
 * If you’d like to show the button somewhere else on the single product page, then
   replace `woocommerce_after_add_to_cart_button` with any other hook from here:
   [https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/](https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/)
 * Also, this custom code should be added to your child theme’s `functions.php` 
   file or via a plugin that allows custom functions to be added, such as [Code Snippets](https://wordpress.org/plugins/code-snippets/).
   Please don’t add custom code directly to your parent theme’s `functions.php` 
   file as this will be wiped entirely when you update.
 * > Also, I would like to add another one in purchase process to go back through
   > cart page
 * The code above can be tweaked to work for your cart/checkout pages — you’ll just
   need to change `woocommerce_after_add_to_cart_button`
 * Cart page hooks here: [https://businessbloomer.com/woocommerce-visual-hook-guide-cart-page/](https://businessbloomer.com/woocommerce-visual-hook-guide-cart-page/)
 * Checkout page hooks here: [https://businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/](https://businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/)
 * You can also then replace `echo ' <button type="button" onclick="history.back();"
   > Go back </button> ';` with:
 * `echo '<a href="URL">Back to cart</a>';`
 * The `URL` need to be changed to the URL of your shop page.
 * Cheers!
 *  Thread Starter [ethink1](https://wordpress.org/support/users/ethink1/)
 * (@ethink1)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/back-button-return-button/#post-9572181)
 * Many thanks to both!
    Back button in single products works well 🙂
 * Sorry for my ignorance but I can’t understand how I can build the code for checkout
   page. If I’ll put the Go Back button next to Place Order the code is woocommerce_review_order_after_submit?
   I tried with some codes but it appears a HTTP ERROR 500.
    I don’t know about 
   php function… could you give me the clue? THANK YOU SO MUCH!!
 *  [Rynald0s](https://wordpress.org/support/users/rynald0s/)
 * (@rynald0s)
 * Automattic Happiness Engineer
 * [8 years, 7 months ago](https://wordpress.org/support/topic/back-button-return-button/#post-9572509)
 * Hi there!
 * > If I’ll put the Go Back button next to Place Order the code is woocommerce_review_order_after_submit?
 * Yes, but if you are going to add it to checkout page then `woocommerce_after_checkout_form`
   would be a better option (imho).
 * You’ll also need to change the function name so that it’s not the same as the
   function you’re using for single products page. Something along these lines:
 *     ```
       add_action( 'woocommerce_after_checkout_form', 'my_second_function_sample', 10 );
       function my_second_function_sample() {
         global $product;
         echo ' <button type="button" onclick="history.back();"> Go back </button> '; 
       }
       ```
   
 * Again, if you need to make it go back to a specific page, then change:
 * `echo ' <button type="button" onclick="history.back();"> Go back </button> ';`
 * with:
 * `echo '<a href="URL">Back to cart</a>';`
 * Remember to change the URL to where you’d like it to link to.
 * Cheers!
    -  This reply was modified 8 years, 7 months ago by [Rynald0s](https://wordpress.org/support/users/rynald0s/).
      Reason: accidentally wrapped in blockquote instead of code
 *  Thread Starter [ethink1](https://wordpress.org/support/users/ethink1/)
 * (@ethink1)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/back-button-return-button/#post-9610956)
 * Many thanks Rynald0s for your help! Very useful! 🙂
 *  [Rynald0s](https://wordpress.org/support/users/rynald0s/)
 * (@rynald0s)
 * Automattic Happiness Engineer
 * [8 years, 6 months ago](https://wordpress.org/support/topic/back-button-return-button/#post-9610971)
 * You’re very welcome!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Back button / Return button’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [back button](https://wordpress.org/support/topic-tag/back-button/)
 * [single product page](https://wordpress.org/support/topic-tag/single-product-page/)

 * 6 replies
 * 3 participants
 * Last reply from: [Rynald0s](https://wordpress.org/support/users/rynald0s/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/back-button-return-button/#post-9610971)
 * Status: resolved