Change status of order if conditions are met
-
Hello,
I thought I had this code pretty well generated but it’s throwing a critical error when I try to implement. Items in our orders have “service” tags that show several different levels of service, depending on what the customer selects.
If a customer checks out with an item with a certain service (example below: mail-in) and the order is paid (goes from pending to processing) we need that status updated to waiting (wc-waiting).
Important note, an order can have more than one item and more than one service tag. This function should change the status if the mail-in service is used in any of the items.
Any help would be great. I’m not a coder by trade but I thought I had this.
function woocommerce_order_status_change_for_waiting_for_key( $order ) { $needs_mailin_instructions = false; foreach ( $order->get_items() as $item ) { if ( isset( $item['service'] ) && $item['service'] === 'mail-in' ) { $needs_mailin_instructions = true; } } if ( $needs_mailin_instructions ) {if ($status == "wc-processing") { $order->update_status( 'waiting', 'order_note' ); } } } add_action('woocommerce_order_status_changed', 'woocommerce_order_status_change_for_waiting_for_key');
The page I need help with: [log in to see the link]
- The topic ‘Change status of order if conditions are met’ is closed to new replies.