I'm having some issues when a customer select a certain delivery option and a certain payment. At the moment we are using bacs and local payment gateways methods to collect the money, and we have local pick up and express delivery options. also, we have custom statuses for woocommerce for each delivery option. The problem occurs when someone asks for express delivery, and he wants to pay with bacs. we tried to assign custom status for each combination but the code is not working, due its selecting the same custom status to every option in the code.
add_action( 'woocommerce_thankyou', 'express_shipping_update_order_status', 10, 1 );
function express_shipping_update_order_status( $order_id ) {
if ( ! $order_id ) return;
$search_rm = 'Despacho Express Todo Santiago (Excluye Padre Hurtado. Recibe al siguiente día hábil)';
$search_estoril = 'Retiro en Tienda Estoril';
$search_vina = 'Retiro en Tienda Reñaca';
$order = wc_get_order( $order_id );
$payment_method=$order->get_payment_method();
foreach($order->get_shipping_methods() as $shipping_item ){
if( strpos( $shipping_item->get_method_title(), $search_rm ) !== false && $payment_method == "bacs"){
$order->update_status('check-payment');
break;
} else {
$order->update_status('express-rm');
break;
}
if( strpos( $shipping_item->get_method_title(), $search_estoril ) !== false && $payment_method == "bacs"){
$order->update_status('check-payment');
break;
} else {
$order->update_status('retiro-rm');
break;
}
if( strpos( $shipping_item->get_method_title(), $search_vina ) !== false && $payment_method == "bacs"){
$order->update_status('check-payment');
break;
} else {
$order->update_status('retiro-vina');
break;
}
}
}
this is the result:
is there any way to fix this? thanks!