Skip to content

Instantly share code, notes, and snippets.

@AladinDridi
Last active May 15, 2018 10:11
Show Gist options
  • Save AladinDridi/442db23c731fae9d6dfb54e10f3e6014 to your computer and use it in GitHub Desktop.
Save AladinDridi/442db23c731fae9d6dfb54e10f3e6014 to your computer and use it in GitHub Desktop.
add_action( 'woocommerce_thankyou', 'ad_redirectcustom');
function ad_redirectcustom( $order_id ){
$order = new WC_Order( $order_id );
$items = $order->get_items();
$product_id=223074;//id of your product
$product_id2=223076;// id of your product
$url ='';// url for the redirection after purchase your product
$url2='';
foreach ( $items as $item ) {
if (($order->status!='failed')&&(product_id==$item['product_id'])) {
wp_redirect($url);
exit;
}
else if (($order->status!='failed')&&($product_id2==$item['product_id'])) {
wp_redirect($url2);
exit; //
}
}
}
@RicoMiller
Copy link

Hey Aladin! That a really awesome great code. Now I'M just going to test it, cause for first its looks a bit confusing. Thank you for your great work!

@RicoMiller
Copy link

BTw I dont understand: What is this? == $product_id2=223076;// must be change by id of you product
foreach ( $items as $item ) {
And what is this for?=== $url2='';

@AladinDridi
Copy link
Author

hi thank u for asking me ;) $prudct_id2 , is the id of your product that u want him redirect to the pages , for example $url='www.google.fr' , then out in the code
if (($order->status!='failed')&&(product_id==$item['product_id'])) {
wp_redirect($url);
exit;
}
so when user purchase that product he will redirect to the url , in my example $url='www.google.fr'

@AladinDridi
Copy link
Author

i 'll create youtube tutorial explain this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment