WooCommerce Redirect To Different Thank You Page Based On Product In Order


You’ll need to have created a custom thank you page and have the URL ready. You’ll also need to the product ID of the product you want to trigger the custom thank you page.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

In some cases, you may wish to redirect users to a different thank you page based on a product purchased in the order. Perhaps there’s specific information you need to tell the customer about and the only practical way is through a custom page. This guides shows you how you can redirect users to a custom thank you page based on a product purchased in the order. You will need the custom thank you page URL and appropriate product ID ready.

* Snippet Name:     Redirect users to a custom WooCommerce thank you page based on a product bought in the order.
* Snippet Author:   ecommercehints.com

add_action( 'template_redirect', 'ecommercehints_product_dependant_thank_you_page' );

function ecommercehints_product_dependant_thank_you_page(){

   if( !is_wc_endpoint_url( 'order-received' ) || empty( $_GET['key'] ) ) {
   $order_id = wc_get_order_id_by_order_key( $_GET['key'] );
   $order = wc_get_order( $order_id );

   foreach( $order->get_items() as $item ) {
      if( $item['product_id'] == 123 ) { // product id here
         wp_redirect( 'YOUR URL' ); // your custom thank you page url here

Snippet Benefits

  • Tailor your thank you page based on a particular product in the order.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

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

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers