Get FAST WordPress Support
World’s Fastest WordPress Support Since 2009  
After Purchase WooCommerce Redirect

After Purchase WooCommerce Redirect

Need to create an after purchase WooCommerce redirect?

WooCommerce is absolutely the number one used eCommerce solution for WordPress.

Directly out of the box when a customer makes a purchase on your WooCommerce shop, it will redirect them to a thank you page with the details of what they purchased.

In some cases you may wish to redirect a customer after that purchase to a custom URL that is not the default area of their order details.

This redirect that you would create would be based on the product that they purchased on your site.

With a nice simple code snippet that would be placed in the act of theme’s functions.php file you can create this after purchase WooCommerce redirect with ease

Follow the steps below to create an after purchase WooCommerce redirect.

Put the below snippet in your active theme’s functions.php file and change the PRODUCT_ID to the product that will be purchased and change CUSTOM_URL to the URL you want them to be redirected to.

/** Custom Redirect after Product Purchase **/

function wcs_redirect_customer ( $order_id ){
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
$_product = wc_get_product( $item['product_id'] );
// Add whatever product id you want below here
if ( $item['product_id'] == PRODUCT_ID ) {
// change below to the URL that you want to send your customer to
wp_redirect('CUSTOM_URL');
}
}
}
add_action( 'woocommerce_thankyou', 'wcs_redirect_customer' );

You will be able to get the PRODUCT_ID by visiting the products page for WooCommerce inside of your WordPress administrative area.

After Purchase WooCommerce Redirect
VISIT WOOCOMMERCE PRODUCTS
After Purchase WooCommerce Redirect
GET PRODUCT ID

Once you have this setup anytime a customer purchases the products with the ID that you’ve placed inside of the code snippet they will be redirected to the custom URL that you selected.

If you wish to do this for multiple products you would create a new function with a unique name for each product that you wish to incorporate this after purchase WooCommerce redirect.

In the example code snippet above the name of this function is “wcs_redirect_customer“.

You would simply create a new unique name for each additional after purchase WooCommerce redirect that you implement inside of your functions.php file.

If you would like to read through an easy FTP guide in order to better understand how you can access and edit your functions.php file please check out the link below.

https://www.wpfixit.com/easy-ftp-guide-for-wordpress-users/

If you have any questions about this process or you get stuck setting this up we would gladly help clarify any part and give you some guidance so you can get this working the way you’d want it to.

Please comment below and we can jump into action to help you out.

4 Comments

Leave a Reply

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