Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

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.

  • Type Action
  • From WooCommerce
  • Since 1.0.0
  • Fired in templates/checkout/thankyou.php

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

Parameters
$order_idint The order ID.

Example: Add a personal note to the thank you page

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

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.