Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashokrane/ed729fe6408fac545d8a243acc14215b to your computer and use it in GitHub Desktop.
Save ashokrane/ed729fe6408fac545d8a243acc14215b to your computer and use it in GitHub Desktop.
Redirect to custom WooCommerce Thank You page based on product attribute id (variation id)
<?php
add_action( 'woocommerce_thankyou', 'redirect_product_attribute_based', 1 );
function redirect_product_attribute_based( $order_id ) {
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
// Add whatever variation id you want below here
if ( isset( $item[ 'variation_id' ] ) && $item[ 'variation_id' ] == 446 ) {
// change below to the URL that you want to send your customer to
wp_redirect( 'http://yoururl.com/custom-thank-you/' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment