A custom thank you page can be very useful specially in WooCommerce Products. A custom thank you page can help you in upsell or after instructions notes for a customer after selling product. This article will help you to add custom thank you page after WooCommerce Product page. You can add any any to a thank you page using a simple redirect action.
Step by Step guide to add custom thank you page for WooCommerce Product
- Open the WooCommerce product on which you wanna add redirect. Copy the ID of the Product (You can get the id from the url when you open the product in dashboard)
- Click on theme editor and select the child theme of your Active theme.
- Click on functions.php file and add the below code with your ID and custom page link.
add_action( 'woocommerce_thankyou', 'redirect_product_based', 1 );
function redirect_product_based ( $order_id ){
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
// Add whatever product id you want below here
if ( $item['product_id'] == 1565 ) {
// change below to the URL that you want to send your customer to
wp_redirect( 'https://www.scriptfeeds.com/thank-you/' );
}
}
}
You can any number custom thank you pages by changing product ID and URL repeating code below in above code.
if ( $item['product_id'] == 1555 ) {
// change below to the URL that you want to send your customer to
wp_redirect( 'https://www.abc.com/thank-you/' );
}
Use the code and let us know how it works.
Happy Coding!
[caldera_form id=”CF60ca2e3ccf64f”]