When a woocommerce order is created the status of the order is "processing". I need to change the default order-status to "pending".
How can I achieve this?
When a woocommerce order is created the status of the order is "processing". I need to change the default order-status to "pending".
How can I achieve this?
The hook woocommerce_thankyou suffers from the problem that you can pay for an order and then close the browser or go somewhere else and therefore never click "Return to Merchant" (which is displayed after paying via paypal) to get to the thankyou page. And then the code will never be executed.
// Rename order status 'Processing' to 'Order Completed' in admin main view - different hook, different value than the other places
add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
function wc_renaming_order_status( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
if ( 'wc-processing' === $key )
$order_statuses['wc-processing'] = _x( 'Order Completed', 'Order status', 'woocommerce' );
}
return $order_statuses;
}
Nowadays, if the payment gateway that you use properly sets the order status using WC_Order->payment_complete()
, you can use the woocommerce_payment_complete_order_status
filter.
This is better than using woocommerce_thankyou
hook since we are setting the order status immediately, rather than applying it after it has been already set.
function h9dx3_override_order_status($status, $order_id, $order) {
if ($status === 'processing') {
$status = 'pending';
}
return $status;
}
add_filter('woocommerce_payment_complete_order_status', 'h9dx3_override_order_status', 10, 3);
Again, this will only work if the payment gateway uses the proper payment_complete
wrapper method rather than setting status directly with set_status
. You can just search the gateway code for 'payment_complete(' and 'set_status(' to see what it does.
If you develop a plugin for everyone, you will be better off with using woocommerce_thankyou
, or you could use a combined approach and use woocommerce_thankyou
as the fallback if the order status was not updated.
The default order status is set by the payment method or the payment gateway.
You could try to use this custom hooked function, but it will not work (as this hook is fired before payment methods and payment gateways):
Apparently each payment method (and payment gateways) are setting the order status (depending on the transaction response for payment gateways)…
Now instead you can update the order status using
woocommerce_thankyou
hook:Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works
Related thread: WooCommerce: Auto complete paid Orders (depending on Payment methods)