Method 1: Add Button via Hook in functions.php
Add this code to your theme’s functions.php file:
function custom_add_go_back_button_thank_you() {
echo '<p style="text-align: center; margin-top: 20px;">
<a href="' . esc_url( wc_get_page_permalink( 'shop' ) ) . '" class="button wc-backward">
← Go Back to Shop
</a>
</p>';
}
add_action( 'woocommerce_thankyou', 'custom_add_go_back_button_thank_you', 20 );
Explanation:
- This hook adds the button to the Thank You page.
- The button links back to the Shop page (
wc_get_page_permalink( 'shop' )
). - You can replace the link with
home_url()
to go back to the homepage.
Method 2: Customize Template (For Full Control)
If you want more control, edit the WooCommerce template:
- Copy this file:
wp-content/plugins/woocommerce/templates/checkout/thankyou.php
- Paste it into your theme:
wp-content/themes/your-theme/woocommerce/checkout/thankyou.php
- Add the button before or after the existing content:
<p style="text-align: center; margin-top: 20px;">
<a href="<?php echo esc_url( wc_get_page_permalink( 'shop' ) ); ?>" class="button wc-backward">
← Go Back to Shop
</a>
</p>
Final Output:
A styled “Go Back to Shop” button will appear on the WooCommerce Thank You page. 🚀
Let me know if you need further customization!