The following code snippet can be used to change the status of an order to ‘completed’ after a payment has been processed successfully by the Subscription for WooCommerce plugin. Simply add the following code snippet to the active child theme function.php.
- Was this article helpful?
- Yes, thanks!Not really
Comments (21)
Federico Van
June 29, 2021
Hi,
great job! I used the code and it works perfectly. But if I wanted to use this hook ‘woocommerce_subscription_renewal_payment_complete’ for Subsciptions renewal order, I could use the same code?
Thanks in advance
Mark
June 30, 2021
Hi Federico,
Could you please brief your exact requirement? This code can be used only to mark all orders as completed after payments.
Federico Van
June 30, 2021
Hi Mark,
and thanks for reply.
I would like to mark as Completed also the orders for renewal of subscriptions after the payment, not only the new orders
Mustafa Akgül
April 11, 2021
Hello there. If a note is written on the order, can I automatically change the order status to pending?
Mark
April 13, 2021
Hi Mustafa,
We do not have any particular hooks in the plugin to achieve this. Since order creation is a default woocommerce action, kindly check in some common woocommerce forums.
Amanda Wyatt
April 9, 2021
I have a very strange question relating to this. I need to auto update my status from “pending” to “processing”. I have an order approval gateway for an account customer – after the order is approved – that counts as the payment. So rather than requesting payment I need a status to be auto updated to processing… is there any help available for me?
Mark
April 16, 2021
Hi Amanda,
If you are required to auto update all pending order to completed, you might need to look for some plugin like this one here. Hope it helps.
Arif Sharif
August 19, 2020
Does this code work for the latest version of woocommerce?
Mark
August 26, 2020
Yes.
Roland Steinmassl
August 28, 2020
yes it works! i just implemented it.
Al Ortiz
July 22, 2020
What if I want to change only “On Hold” orders to “processing”, can I still use the above code?
Mark
August 7, 2020
Hi Al,
To change from on hold to processing orders, you should try the following:
add_action( 'woocommerce_thankyou', 'woocommerce_auto_processing_orders');
function woocommerce_auto_processing_orders( $order_id ) {
if ( ! $order_id )
return;
$order = wc_get_order( $order_id );
// If order is "on-hold" update status to "processing"
if( $order->has_status( 'on-hold' ) ) {
$order->update_status( 'processing' );
}
}
Roland Steinmassl
August 31, 2020
Hi Mark.
I switched it so that “processing” always goes to “on-hold” – BUT the problem is that i only need that after a successful payment – not when i set “processing” manually. Any ideas? Thanks, Roland
arash
June 14, 2020
it is better to use something like this:
add_filter( ‘woocommerce_payment_complete_order_status’, ‘ar_woocommerce_payment_complete_order_status’, 10, 2 );
if(!function_exists(‘ar_woocommerce_payment_complete_order_status’)){
function ar_woocommerce_payment_complete_order_status( $order_status, $order_id ) {
$order = new WC_Order( $order_id );
if ( ‘processing’ == $order_status && ( ‘on-hold’ == $order->get_status() || ‘pending’ == $order->get_status() || ‘failed’ == $order->get_status() ) ) {
return ‘completed’;
}
return $order_status;
}
}
Chris
April 9, 2019
This does not look like it targets orders created via a subscription. I sell physical products too. If I add this code, it looks like its going to mark my physical products as Completed too, “and never make it in to shipstation” could you confirm this?
Alan
April 9, 2019
Hi Chris,
If the above code snippet is used all the order status will be changed to completed from processing. If you required to change the status of only the subscription orders we can customize the snippet for you. Please reach us via support if you are interested in having the customized code snippet.
Colin
September 5, 2018
Hi Safwana
So adding the above code will just mark the original order as complete, but leave all the recurring payment alone? i.e. if a customers has 5 recurring payments, the original order will say complete, but the remaining 4 payments will all work fine and live in the WebToffee Subscriptions tab?
Thanks
Safwana
September 5, 2018
Hi Colin,
The above code snippet will change the status of orders to “completed” when it comes in as “processing”. Also, if the recurring order comes in the processing status, that will also be marked as completed.
If the parent order is set to complete from processing, that will not affect the remaining recurring orders and they will occur as expected.
Rob
August 19, 2018
Does this work for recurring subscriptions?
At the moment, only the first payment is taken and the subscription then shows as ‘on hold’.
I’ve done something similar to the above snippet for virtual products setting them to complete when payment is taken, but the subscriptions have a status of ‘active’ when complete.
So does this work, or should I just change it to $order->update_status(‘active’); ?
(I don’t have access to the site’s database to see what it’s actually stored as).
Rob
August 19, 2018
I think I get it now. Subscriptions aren’t orders, so when the order is set as complete the subscription status should update.
Safwana
August 20, 2018
Hi Rob,
The above snippet will let you mark the parent order as complete, which would be set to processing by default after payment processing. The subscription order status will be set to active if the order status is either processing or complete, considering the payment completed successfully.
The issue could be related to payment failure. Please reach us via our support desk and share us the version of the plugin and the payment gateway plugin you are using so that the developers can have a look.