Stay on top with regular WordPress updates.
Subscribe to our newsletter(s) and get the latest stories in your mailbox!
Stay on top with regular WordPress updates.
Subscribe to our newsletter(s) and get the latest stories in your mailbox!
This code will redirect to a custom URL after checkout based on the array of product ids in the code.
add_action(‘woocommerce_thankyou’, ‘redirect_to_url_based_on_product_id’); function redirect_to_url_based_on_product_id( $order_id ) { if ( ! $order_id ) return; $order = wc_get_order($order_id); $survey_product_ids = [387]; $survey_url = ‘https://example.com’; foreach ($order->get_items() as $item) { if (in_array($item->get_product_id(), $survey_product_ids)) { wp_redirect($survey_url); exit; } } }
Add or change 1 or more product ids in this line :
$survey_product_ids = [387, 888, 999];
This is the first part of the article