WooCommerce Redirect to Custom Thank you Page

WooCommerce Redirect to Custom Thank you Page
420 Views
4.3
(7607)

The below code allows you to redirect to a custom page after the user has completed a purchase when using the WooCommerce plugin. Simply add the below code to the active child theme’s function.php and replace the URL in the function wp_redirect() with the desired page.

PHP Snippet: WooCommerce Redirect to Custom Thank you Page

/**
 * @snippet       WooCommerce: Redirect to Custom Thank you Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */
  
add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
  
function bbloomer_redirectcustom( $order_id ){
    $order = wc_get_order( $order_id );
    $url = 'https://yoursite.com/custom-url';
    if ( ! $order->has_status( 'failed' ) ) {
        wp_safe_redirect( $url );
        exit;
    }
}

“I couldn’t get redirection to work.” I was updating a client’s website and tried using redirection, but it didn’t help. Even using a redirection plugin called Simple 301 Redirects did not solve the problem.

Here’s what I discovered: When changing the settings for the WooCommerce endpoint, my client accidentally added an extra space between “Order” and “Received” (the image below shows the text that was incorrectly interpreted by Google. was translated into Danish.

How useful was this blog?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 7607

No votes so far! Be the first to rate this blog.

Leave a comment

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