Skip to content

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

woocommerce_order_status_completed

Fires when an order's status changes to Completed. Use it to run tasks once an order has been fulfilled.

  • Type Action
  • From WooCommerce
  • Since 1.0.0
  • Fired in includes/class-wc-order.php

When it fires

This is the 'completed' form of the dynamic woocommerce_order_status_{status} action. WooCommerce fires it when an order is saved with a new status of Completed, whether that happens in the admin, in bulk, or through a payment method or plugin.

It runs after the new status has been saved and before the order note about the change is added. WooCommerce uses it too, for example to send the Completed order email.

Parameters

Parameters
$order_idint Order ID.
$orderWC_Order Order object.
$status_transitionarray Status transition data: 'from', 'to', 'note' and 'manual'.

Example: Count each customer's completed orders

PHP
add_action( 'woocommerce_order_status_completed', function ( $order_id, $order ) {
	$customer_id = $order->get_customer_id();
	if ( ! $customer_id || $order->get_meta( '_my_completion_counted' ) ) {
		return;
	}
	$count = (int) get_user_meta( $customer_id, '_my_completed_orders', true );
	update_user_meta( $customer_id, '_my_completed_orders', $count + 1 );
	$order->update_meta_data( '_my_completion_counted', 'yes' );
	$order->save_meta_data();
}, 10, 2 );

Good to know

  • It fires again if an order is moved away from Completed and back, so guard one-off work with order meta, as in the example.
  • Guest orders have no customer ID, so check it before saving anything to a user.
  • Set the accepted arguments to 2 or 3 when you add the action, or you'll only receive $order_id.

Move your snippets over this afternoon.

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