# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, thank-you, redirects, checkout
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-thank-you-page-per-product/

## Code

```php
$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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Different Thank-You Page per Product" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
