Last active
September 27, 2017 04:04
-
-
Save slash1andy/970f81db419eb01c9761 to your computer and use it in GitHub Desktop.
WooCommerce Redirect to Custom URL Based on Product Purchased
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wcs_redirect_product_based ( $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'] == 70 ) { | |
// change below to the URL that you want to send your customer to | |
wp_redirect('http://www.yoururl.com/your-thank-you-page'); | |
} | |
} | |
} | |
add_action( 'woocommerce_thankyou', 'wcs_redirect_product_based' ); |
(thumbsup)
how do i do this for multipul products. Each product has a different thank you page i need to redirect to
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice one @slash1andy but try use the new wc_get_order functions etc. like https://gist.github.com/bryceadams/34db2db167f3c57b48ae