Skip to content

Instantly share code, notes, and snippets.

@deeman
Created August 18, 2019 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deeman/22fd37523d80b4367789eba5411e24a3 to your computer and use it in GitHub Desktop.
Save deeman/22fd37523d80b4367789eba5411e24a3 to your computer and use it in GitHub Desktop.
Smart History Button - WooCommerce Single Product Page
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.
For visual hooks, visit
* Your Own tweaks
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 to whatever you prefer.
* Visual Hooks
1. Single product page here: https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/
2. Cart page hooks here: https://businessbloomer.com/woocommerce-visual-hook-guide-cart-page/
3. Checkout page hooks here: https://businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/
//History Button on WooCommerce 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> ';
}
//*Possible modifications
// Change: echo ' <button type="button" onclick="history.back();"> Go back </button> ';
// To: echo '<a href="URL">Back to cart</a>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment