woocommerce_thankyou

The woocommerce_thankyou action lets you display content on a WooCommerce order confirmation page. It receives one argument, $order_id (integer), and does not return a value. The classic checkout/thankyou.php template calls it when an order is available, including on the failed-order screen.

Display a note for a valid order

add_action( 'woocommerce_thankyou', function ( $order_id ) {
    $order = wc_get_order( $order_id );

    if ( ! $order || $order->has_status( 'failed' ) ) {
        return;
    }

    echo '<p class="order-note">' .
        esc_html( 'Please save your order number for your records.' ) .
        '</p>';
}, 20 );

The callback retrieves the order and skips the message when the lookup fails or the status is failed. Add it in a site-specific plugin or child theme's functions.php, then check successful and failed payment outcomes on a staging site.

This is a page-rendering hook, not proof of a new payment or a one-time purchase event. Refreshing or revisiting a confirmation page can execute it again. Do not use it directly for sending one-time emails, reducing stock, or marking orders paid. Those operations belong in appropriate order lifecycle handling, with safeguards against duplicate work. The woocommerce_order_status_changed action documents status transitions, but its suitability depends on which business event you need.

WooCommerce's Order Confirmation Additional Information block also invokes the action when the visitor has permission to view the order. It handles core output separately, so the position can differ from the classic template.