php - WooCommerce change status for BACS orders based on specific shipping methods
one text
Solution:
Try the following instead (code is commented):
add_action( 'woocommerce_thankyou', 'bacs_order_payment_pending_order_status_shipping_method', 10, 1 );
function bacs_order_payment_pending_order_status_shipping_method( $order_id ) {
// Get WC_Order object from the order Id
$order = wc_get_order( $order_id );
// Check that we get a WC_Order
if ( is_a( $order, 'WC_Order' ) ) {
// Shipping Methods to check
$shipping_methods_to_check = array( 'flat_rate', 'request_shipping_quote' );
$condition = $order->get_payment_method() == 'bacs' && $order->has_status( 'on-hold' );
// Loop through shipping items (objects)
foreach($order->get_shipping_methods() as $shipping_item ){
// Check for matched defined shipping methods
if( in_array( $shipping_item->get_method_id(), $shipping_methods_to_check ) && $condition ){
$order->update_status( 'custom-status' ); // Change order status
return; // Exit
}
}
}
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
related: Change Woocommerce Order Status based on Shipping Method
Source