Payment Complete Hooks

There are three different action hooks I would like to talk about.

All of those hooks are fired when an order is either paid or doesn’t require a payment (Cash on Delivery for example). They also apply for custom payment gateways.

The first hook, woocommerce_pre_payment_complete applies at the very beginning and doesn’t depend on order status.

add_action( 'woocommerce_pre_payment_complete', 'rudr_pre_complete' );

function rudr_pre_complete( $order_id ) {
	
	$order = wc_get_order( $order_id );
	// get the order data and do anything
	
}

The next one, woocommerce_payment_complete will be fired only if an order has one of the following order status on-hold, pending, failed, cancelled, but please keep in mind that this list of statuses can also be filtered with woocommerce_valid_order_statuses_for_payment_complete.

But before the hook applies, WooCommerce is going to change the order status either to processing or completed, which also can be filtered with woocommerce_payment_complete_order_status.

add_action( 'woocommerce_payment_complete', 'rudr_complete' );

function rudr_complete( $order_id ) {
	
	$order = wc_get_order( $order_id );
	// do anything
	
}

And the last but not least, woocommerce_payment_complete_order_status_$status will be fired for the rest of the order statuses.

add_action( 'woocommerce_payment_complete_order_status_processing', 'rudr_complete_for_status' );
add_action( 'woocommerce_payment_complete_order_status_completed', 'rudr_complete_for_status' );

function rudr_complete_for_status( $order_id ){
	
	// do anything
	
}

When I say “do anything”, I do not actually mean absolutely anything, for example, if you would like to perform a redirect, it is better to be done with template_redirect hook like I described here.

In some tutorials I also saw woocommerce_payment_complete_order_status and woocommerce_order_status_completed but I think their usage is less correct.

Need custom coding help with WooCommerce payment gateways? – Contact me.

Misha Rudrastyh

Misha Rudrastyh

I develop websites since 2008, so it is total of 13 years of experience, oh my gosh. Most of all I love love love to create websites with WordPress and Gutenberg, some ideas and thoughts I share throughout my blog.

Need some developer help? Contact me