Created
August 18, 2019 13:39
-
-
Save deeman/22fd37523d80b4367789eba5411e24a3 to your computer and use it in GitHub Desktop.
Smart History Button - WooCommerce Single Product Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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