Different Thank-You Page per Product
Sends customers to a specific page after checkout when their order contains a certain product, such as onboarding steps for a course or setup guide for a device.
Opens WPIDE on
Code
$wpide_product_thanks = array( // Product ID => page ID.
123 => 456,
124 => 789,
);
add_filter( 'woocommerce_get_checkout_order_received_url', function ( $url, $order ) use ( $wpide_product_thanks ) {
if ( ! $order instanceof WC_Order || $order->has_status( 'failed' ) ) {
return $url;
}
foreach ( $order->get_items() as $item ) {
$page = $wpide_product_thanks[ $item->get_product_id() ] ?? 0;
if ( $page && 'publish' === get_post_status( $page ) ) {
return add_query_arg( array( 'order_id' => $order->get_id(), 'key' => $order->get_order_key() ), get_permalink( $page ) );
}
}
return $url;
}, 20, 2 );
Notes
The first matching product wins, and the order key is passed along so your page can still show the order details.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.