How to Redirect to Custom Thank You Page in WooCommerce?

Image showing how to redirect to custom Thank You Page

In WooCommerce, you can redirect your customers to a beautifully designed Thank You page. You just need to add simple PHP code to your functions.php. After that, you can redirect your visitors to a custom URL. So, in this article, you will learn to redirect to custom Thank You Page in WooCommerce. 

Following this way, your visitors won’t see the default order received page. Instead, the users will see a customized Thank You page. You can also showcase product upsells, social media handles, etc over this page. This could be a good chance to encourage additional sales. As these visitors have just made a purchase on your website, the chances are they will buy more. 

PHP Snippet: WooCommerce Redirect to Custom Thank You Page

add_action( 'woocommerce_thankyou', 'phpsof_redirectcustom');
function phpsof_redirectcustom( $order_id ){
    $order = wc_get_order( $order_id );
    $url = '';
    if ( ! $order->has_status( 'failed' ) ) {
        wp_safe_redirect( $url );

Failed to Redirect visitors to Thank You page?

Sometimes, you might fail transferring visitors to the Thank You page. If that’s the case, then you need to identify the cause. Make sure that there is no empty space between “Order” and “Received” in WooCommerce endpoint settings. If you have left blank space, then even 301 redirects plugin won’t work. 

Image showing empty space between order and received in WooCommerce endpoint settings

Where do you add this snippet?

So, this is how you can redirect to custom Thank You Page in WooCommerce. Also, it is easier to activate this function with this code. So, to apply this code, just add this PHP snippet at your child theme function.php file’s bottom. It should be placed before “?>”, if you have it there. Apart from this, CSS goes in your child theme style.css file. Make sure that you are editing these files in a right manner for best results.

Is this snippet still valid?

So, this is how you can learn about redirect to custom Thank You Page in WooCommerce. I have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. Let me know if everything works as expected when you code. Share it further if you find this snippet useful for you and it had saved your time. 

Also Read, How to Attach files to Order Emails in WooCommerce?

How to Show Product Upsells at Thank You Page in WooCommerce?

Important links: WooCommerce –