79264402

Date: 2024-12-09 09:16:25
Score: 0.5
Natty:
Report link

Key Changes:

1.Simplified Shipping Method IDs: Combined all express shipping methods into a single array.

2.Correct Method ID Format: Ensure the method IDs match the format returned by get_method_id(), which typically includes the method type and instance ID (e.g., flat_rate:25).

3.Status Update: Changed the status to 'priority' to match your requirement.

add_action( 'woocommerce_thankyou', 'shipping_method_update_order_status', 10, 1 );
function shipping_method_update_order_status( $order_id ) {
    if ( ! $order_id ) return;

    // Define your express shipping methods IDs
    $express_shipping_methods = array('flat_rate:25', 'flat_rate:26', 'flat_rate:27', 'flat_rate:28');

    // Get an instance of the WC_Order object
    $order = wc_get_order( $order_id );

    // Get the WC_Order_Item_Shipping object data
    foreach ( $order->get_shipping_methods() as $shipping_item ) {
        // Check if the shipping method is one of the express options
        if ( in_array( $shipping_item->get_method_id(), $express_shipping_methods ) && ! $order->has_status('priority') ) {
            $order->update_status('priority'); // Update the order status to 'priority'
            break; // Stop the loop
        }
    }
}
Reasons:
  • Blacklisted phrase (1): thankyou
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Seven