I use wooCommerce theme and this my working redirect after checkout per product code :
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'] == 3531 ) {
// URL
wp_redirect( 'www...' );
}
if ( $item['product_id'] == 35 ) {
// URL
wp_redirect( 'www....' );
}
}
}
Now i want code working for multiple products like :
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'] == 331, 332, ... ) {
// URL
wp_redirect( 'www...' );
}
if ( $item['product_id'] == 35, 36, ... ) {
// URL
wp_redirect( 'www....' );
}
}
}
Any help with this to apply for multiple products please.