When you are selling products that require specific after-sale service on your WooCommerce store, you may want to create WooCommerce redirect after checkout per product.
Ideally, for every product, the user will be redirected to a specific page.
In the previous post, I shared in detail how to create WooCommerce redirect after checkout, and in another post how to create a WooCommerce redirect after logout.
WooCommerce Redirect After Checkout Per Product
In this post, I am going to show you how to quickly create a custom WooCommerce redirect after checkout for each product that is bought individually.
Redirect After Checkout Per Product Code Snippet
To create the WooCommerce Redirect After Checkout Per Product using a code snippet, you need to add the code snippet to your functions.php file and you also need to understand how the code works.
The idea is to get the product in the cart and use the ID to redirect the user after checkout if the product is in the cart. You can implement this in the code as shared in the code snippet below :
add_action( 'woocommerce_thankyou', 'njengah_redirect_after_checkout_per_product', 1 ); function njengah_redirect_after_checkout_per_product ( $order_id ){ $order = wc_get_order( $order_id ); foreach( $order->get_items() as $item ) { // Change the product_id to match the product_id of your choice if ( $item['product_id'] == 1 ) { // Redirect URL wp_redirect( 'example.com' ); } else { // Alternative Redirect UR wp_redirect( 'example.com' ); } } }
You need to edit the code above with the right product ID and the redirect URL for it to work.
Redirect After Checkout Per Product Plugin
If you require a quick plugin solution, I created a plugin WRAC that comes with excellent conditional redirects that allow users to create WooCommerce redirects after checkout for each product as you can see in the image below.
Conclusion
In this post, we have covered the way you can create WooCommerce Redirect After Checkout Per Product both using a plugin and also using a code snippet.
If you would like to implement this solution and you are not sure how to get it done, you can feel free to get in touch.
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- How to Create Order Programmatically WooCommerce
- How to Redirect to Cart after Login in WooCommerce
- How to Get Current Product Category Name in WooCommerce
- How to Create WooCommerce Storefront Child Theme [Complete Guide]
- How to Redirect User If Not Logged in WordPress » Page Redirect
- How to Check if a User is Logged In to WordPress
- WooCommerce Mobile Checkout Optimization Quick Guide
- How to Create My Account Page In WooCommerce
- WooCommerce Login Redirect Hook Explained with Example
- How to Create WooCommerce Login Logout Shortcode
- How to Add WooCommerce My Account Page Redirect
- How to Create WooCommerce Add to Cart Button by Product Id
- How to Create WooCommerce After Login Redirect to Homepage
- How to use do_shortcode in WordPress (PHP)
- WooCommerce Checkout Optimization Quick Guide
- How to Clear Cart on Logout In WooCommerce
- How to Create WooCommerce Clear Cart Button Shortcode
- How to Get Checkout URL In WooCommerce
- How to Get WooCommerce Checkout Country Dropdown
- How to Hide Price and Add to Cart for Logged Out Users WooCommerce