Reputation: 23
I would like to change the woocommerce order status auotmatically from "on-hold" to "processing" for every new order, except for payment method BACS (Direct Bank Transfer). I already found this code, but do not know how to adapt it to exclude payments made with BACS.
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' );
}
}
Thank you for your help!
Upvotes: 1
Views: 804
Reputation: 253773
Update related to your comment based on WooCommerce: Auto complete paid orders answer thread.
Try the following:
add_action( 'woocommerce_payment_complete_order_status', 'wc_auto_complete_paid_order', 10, 3 );
function wc_auto_complete_paid_order( $status, $order_id, $order ) {
return 'processing';
}
It should work.
Original answer (based on the question code):
You can use WC_Order
get_payment_method()
method as follow:
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" except for "BACS" payments
if( $order->has_status( 'on-hold' ) && $order->get_payment_method() !== 'bacs' ) {
$order->update_status( 'processing' );
}
}
It should work.
Related: WooCommerce: Auto complete paid orders
Upvotes: 1