woocommerce_payment_complete Hook: Examples [Guide]

WooCommerce payment complete hook

A payment gateway can confirm that money arrived, but your own code often needs to react at that exact moment: log the transaction, notify a warehouse, or unlock access to a digital product. The woocommerce_payment_complete hook is where WooCommerce tells you a payment succeeded.

This guide covers what the hook receives, when it fires, how to run code on paid orders, and the mistakes that make it silently do nothing.

What woocommerce_payment_complete Does

It is an action hook. Gateways do not fire it directly. They call $order->payment_complete( $transaction_id ), and that method sets the new order status, stores the transaction ID, and then runs the hook. Your function attaches to the hook and receives the order ID and the transaction ID.

Hook Signature and Parameters

WooCommerce runs the hook with two arguments:

ArgumentTypePurpose
$order_idintID of the paid order. Pass it to wc_get_order() to load the order object.
$transaction_idstringTransaction ID from the gateway. It may be empty, so check it before you use it.

Attach your function with add_action() and pass 10, 2 as the last two arguments. Without the 2, WordPress passes only the order ID.

When the Hook Fires

The hook runs once for each successful payment_complete() call. Gateways usually make that call when the provider confirms the charge. That can happen during the checkout request or later, through a webhook.

Before the Hook: woocommerce_pre_payment_complete

WooCommerce fires woocommerce_pre_payment_complete at the start of payment_complete(), before the status changes. Use it to prepare for a payment. Use the main hook for anything that must run after the payment is recorded.

Which Order Statuses Qualify

payment_complete() only works on orders in an allowed status. By default, those are pending payment, on hold, failed, and cancelled. Change the list with the woocommerce_valid_order_statuses_for_payment_complete filter. If the order is already in another status, such as processing, the method returns early and the hook does not fire.

Run Code After a Payment Completes

The examples below go in a site-specific plugin or your child theme’s functions.php. Each one loads the order with wc_get_order(), which returns false if the order does not exist.

Log the Transaction ID

The simplest use is an order note. The admin can then see the transaction ID on the order screen without opening the gateway dashboard.

<?php
add_action( 'woocommerce_payment_complete', 'my_log_transaction_id', 10, 2 );

function my_log_transaction_id( $order_id, $transaction_id ) {
    $order = wc_get_order( $order_id );

    if ( ! $order ) {
        return;
    }

    $order->add_order_note(
        sprintf( 'Payment received. Transaction ID: %s', $transaction_id )
    );
}

Flag Orders From One Gateway

Use get_payment_method() to run code for one gateway only. Replace 'stripe' with your gateway’s ID. This example saves the transaction ID as order meta for that gateway.

<?php
add_action( 'woocommerce_payment_complete', 'my_flag_gateway_orders', 10, 2 );

function my_flag_gateway_orders( $order_id, $transaction_id ) {
    $order = wc_get_order( $order_id );

    if ( ! $order || 'stripe' !== $order->get_payment_method() ) {
        return;
    }

    $order->update_meta_data( '_my_gateway_transaction_id', $transaction_id );
    $order->save();
}

Change the Status After Payment

By default, a paid order moves to processing. Virtual and downloadable products move to completed. Use the woocommerce_payment_complete_order_status filter to change that status. The filter receives the status and the order ID, and it must return a status slug such as on-hold. The example below holds large orders for review:

<?php
add_filter( 'woocommerce_payment_complete_order_status', 'my_hold_large_orders', 10, 2 );

function my_hold_large_orders( $status, $order_id ) {
    $order = wc_get_order( $order_id );

    if ( $order && $order->get_total() > 1000 ) {
        return 'on-hold';
    }

    return $status;
}

Tip: Check the order status in your filter before you return a new one. Otherwise you can override a status that another plugin set on purpose.

Test the Hook

Test on a staging site first. Place a test order with a gateway in test mode, or call payment_complete() on a pending order from a temporary snippet. Then check these three things:

  • Order notes: the transaction ID note appears once.
  • Order status: the status matches what your filter returns.
  • Order meta: the saved flag exists for orders from the target gateway only.
WordPress order notes panel showing a private note that reads Payment received. Transaction ID

The note above is a private note that my_log_transaction_id() adds with add_order_note(). Stripe charge notes on live orders come from the Stripe plugin, not from this hook.

Common Mistakes

  • Missing the second argument. Without 10, 2 in add_action(), your function never receives the transaction ID.
  • Expecting it on manual status changes. Moving an order to processing from the admin does not call payment_complete(), so the hook does not fire.
  • Assuming the transaction ID exists. Some gateways and manual flows pass no value. Check it before you store or display it.
  • Skipping the order check. wc_get_order() returns false for a missing order, and calling a method on it causes a fatal error.

FAQs About woocommerce_payment_complete

Does the Hook Fire for Cash on Delivery?

Often not. Cash on delivery usually does not call payment_complete() at checkout, so check the gateway code. If you need a trigger for that case, use an order status hook instead.

Can the Hook Run Twice for One Order?

Normally not. Once the order is paid, its status is no longer in the valid list, so a second call returns early. A gateway webhook retry can still reach your code through another path, so keep your own logic safe to repeat.

How Is It Different From woocommerce_order_status_completed?

woocommerce_order_status_completed fires whenever an order reaches completed, including when an admin changes it by hand. woocommerce_payment_complete fires only when payment_complete() runs, and it passes the transaction ID.

Do I Need to Call payment_complete() Myself?

Only for a custom gateway or an offline flow where you confirm payment yourself. Built-in gateways call it for you. Pass the transaction ID so the hook receives it.

Conclusion

The woocommerce_payment_complete hook is the reliable point for work that should happen only after payment is recorded. Attach with two arguments, respect the valid status list, and use the status filter when paid orders need review. For the order methods used above, see the WC_Order object guide.

Need payment logic built for your store? Hire a WooCommerce developer, or reach out to me directly.

About The Author

Picture of Andriy Haydash

Andriy Haydash

Andriy Haydash is a WordPress Expert who helps people build and launch successful WordPress membership and e-learning websites.

Note: Not all of the articles are written directly by me.
Affiliate Disclaimer: Some links in the post may be my affiliate links

Kinsta - Managed Hosting for WordPress

Before YOU Leave...
Join My Newsletter

Get practical tips & tricks on how to start, grow and market your course/membership site.