Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Frontend Snippets] Automatically complete all orders
/**
* Auto Complete all WooCommerce orders.
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order->update_status( 'completed' );
}
@liakatsagoni
Copy link

Does this work if a place it in a CodeSnippet plug in???

@lnorton89
Copy link

I've noticed this works intermittently, not sure the cause.

@vmulot
Copy link

vmulot commented Sep 12, 2019

Same here, some times it works, but not always, i'm investigating...

@mdqmatias
Copy link

Hi, this code auto complete PAID ORDERS? That is only i need, that auto complete only if the order is paid.

@matthew-asuncion
Copy link

It works for all orders even unpaid. It must work only for paid orders.

@jreitter
Copy link

Doesn't work for my case because I don't display a "Thank You" page, I guess. Any other way to hiik it so something else?

@giacomoferretti
Copy link

Doesn't work for my case because I don't display a "Thank You" page, I guess. Any other way to hiik it so something else?

You could hook woocommerce_payment_complete'. For a full list of hooks, check this.

@marisalesduarte
Copy link

For orders in process, after receiving payment, change the if to:
if ( $order_status == 'processing' )

This worked for me, for paid orders only!

@sverleis
Copy link

Is there any way of adapting this snippet to work for recurring subscription renewals, using WooCommerce Subscriptions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment