Reputation:
In WooCommerce, I need all my orders to go immediately to "processing" status to have the order-processing email sent directly when the order is processed.
By default, this behavior exist for Paypal and COD orders, but not for BACS and Cheque where the default status is on-hold
.
I tried several snippets like this one:
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_process_order' );
function custom_woocommerce_auto_process_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order->update_status( 'processing' );
}
But this doesn't work, the order still shows up in "on-hold" status and the processing email notification is not sent. Now I just found a this snippet:
add_filter( 'woocommerce_bacs_process_payment_order_status', function( $status = 'on_hold', $order = null ) {
return 'processing';
}, 10, 2 );
And it works, but only for "BACS". How can I adapt it to also work for "Cheque" orders?
Upvotes: 3
Views: 6323
Reputation: 253867
The filter hook
woocommerce_cheque_process_payment_order_status
is not yet implemented in Woocommerce 3.5.7 … if you look to the file located in your woocommerce plugin under:
includes
>gateways
>cheque
>class-wc-gateway-cheque.php
, the hook is missing (line122
):$order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
But on Github WC version 3.5.7 for
class-wc-gateway-cheque.php
file, the hook exist (line122
):$order->update_status( apply_filters( 'woocommerce_cheque_process_payment_order_status', 'on-hold', $order ), _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
The hook will is planed to be available next WooCommerce 3.6 release, see the file change on Woocommerce Github. It's tagged 3.6.0-rc.2
and 3.6.0-beta.1
So it will be possible to change the default order status to "processing" for "bacs" and "cheque" payment methods, using the following:
add_filter( 'woocommerce_bacs_process_payment_order_status','filter_process_payment_order_status_callback', 10, 2 );
add_filter( 'woocommerce_cheque_process_payment_order_status','filter_process_payment_order_status_callback', 10, 2 );
function filter_process_payment_order_status_callback( $status, $order ) {
return 'processing';
}
Code goes in functions.php file of your active child theme (or active theme).
Upvotes: 6
Reputation: 4858
You're almost there. Right now you are adding a filter for the BACS
hook. There is a similar hook for Cheque
payment method.
Simply add the following code:
add_filter(
'woocommerce_cheque_process_payment_order_status',
function( $status = 'on_hold', $order = null ) {
return 'processing';
}, 10, 2
);
It does the exact same, but just for the Cheque
orders.
Upvotes: 0