In this tutorial we’ll learn how to redirect customers to a custom thank you page.
We can achieve this by using one of woocemmerce’s default hook.
Our team at Themelocation is comprised of WordPress developers of high expertise
- We can maintain, support and manage your single, or all your clients, website with dedication
- Our skills are at your disposal.
First of all create a custom page where you want your customers be redirected to upon successful order completion.
I’ve created a custom thank you page:
Now we need to redirect our customers to this page upon successful order completion.
To do this add the following lines of code at the end of your theme’s functions.php file:
add_action( 'woocommerce_thankyou', function( $order_id ){ $order = new WC_Order( $order_id ); $url = 'http://localhost/wordpress/thank-you/'; if ( $order->status != 'failed' ) { echo "<script type='text/javascript'>window.location = '".$url."'</script>"; } });
You can access functions.php file here:
Replace the url of the page you wantyour customers to redirect with the one in the code.
Now whenever a customer will make a successful login, they will be redirected to the custom page instead of default checkout page.
Now, add products in cart and proceed to checkout.
And you’ll be redirected to custom thank you page!