woocommerce_thankyou
Fires on the order received (thank you) page after an order is placed, with the order ID. Use it for order-specific content.
When it fires
WooCommerce fires this action near the end of the thank you template (checkout/thankyou.php), after the order overview. It passes the order ID, and WooCommerce uses the hook at priority 10 to print the order details table.
In block themes, the Order Confirmation template fires it through the Additional Information block, so it only runs if that block is in the template.
Parameters
$order_idint |
The order ID. |
|---|
Example: Add a personal note to the thank you page
add_action( 'woocommerce_thankyou', function ( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order || $order->has_status( 'failed' ) ) {
return;
}
printf(
'<p class="thankyou-note">%s</p>',
esc_html(
sprintf(
/* translators: %s: customer's first name */
__( 'Thanks, %s. We will email you as soon as your order ships.', 'my-snippets' ),
$order->get_billing_first_name()
)
)
);
}, 5 );
Good to know
- The page can be reloaded or revisited, so this hook can fire many times for one order. For one-off tasks, use order hooks such as woocommerce_payment_complete or woocommerce_order_status_completed.
- It also fires for failed orders, so check the status as in the example.
- Each payment method has its own variant, woocommerce_thankyou_{payment_method}, which runs just before this one.