How can we change order status to on-hold direct before processing(default) order email trigger?
Both Action trigger after processing email.

But I need hook before processing email (default status).

Please help

This is my code:

add_action('woocommerce_checkout_order_processed','change_backordered_order_status', 10, 1 );

// Or

add_action('woocommerce_thankyou','change_backordered_order_status', 10, 1 );

// =========================================================================

function change_backordered_order_status($order_id)
{
        $status = get_post_meta($order_id,"custom_hold_status",true);
        if($status != "done"){
            $order = new WC_Order($order_id);
            $items = $order->get_items();
            $backorder = FALSE;
            foreach ($items as $item) {
                if ($item['Backordered']) {
                    $backorder = TRUE;
                    break;
                }
            }
            if($backorder){
                $order->update_status('on-hold'); 
            }
            foreach ( $items as $item ) {
               $product_id = $item['product_id'];
               $variation_id = $item['variation_id']; 
               $simple_product_sale_price = get_post_meta($product_id, '_sale_price', true);
               $variation_sale_price = get_post_meta($variation_id, '_sale_price', true);
               if($simple_product_sale_price || $variation_sale_price){
                 $order->update_status('on-hold'); 
               }
            }
            add_post_meta($order_id,'custom_hold_status',"done",true);
        }
    }

Read more here: Change order status to on-hold directly before processing(default) order email trigger?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: