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.