Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Woocommerce 如何按产品类别将订单状态更改为自定义状态_Woocommerce - Fatal编程技术网

Woocommerce 如何按产品类别将订单状态更改为自定义状态

Woocommerce 如何按产品类别将订单状态更改为自定义状态,woocommerce,Woocommerce,我希望它自动切换到特殊订单状态时,订单是从我已确定的产品类别在Woocommerce。代码应该是怎样的,你能帮我吗 比如,;如果订单中有个性化产品类别的产品,我希望它自动切换到“wc准备”状态 谢谢未经测试的代码,但应该可以做到这一点 add_action( 'woocommerce_checkout_order_processed', 'custom_order_status_by_cat', 10, 3 ); function custom_order_status_by_cat( $ord

我希望它自动切换到特殊订单状态时,订单是从我已确定的产品类别在Woocommerce。代码应该是怎样的,你能帮我吗

比如,;如果订单中有个性化产品类别的产品,我希望它自动切换到“wc准备”状态


谢谢

未经测试的代码,但应该可以做到这一点

add_action( 'woocommerce_checkout_order_processed', 'custom_order_status_by_cat', 10, 3 );
function custom_order_status_by_cat( $order_id, $posted_data, $order ){
    $items = $order->get_items(); 
    foreach ( $items as $item ) {      
      $product_id = $item->get_product_id();  
      if ( has_term( 'special-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e special-flowers
         $order->update_status( 'wc-prepare' ); // your status here
         break;
      }
    }
}
如果你想为多只猫做这个

add_action( 'woocommerce_checkout_order_processed', 'custom_order_status_by_cat', 10, 3 );
function custom_order_status_by_cat( $order_id, $posted_data, $order ){
    $items = $order->get_items(); 
    foreach ( $items as $item ) {      
      $product_id = $item->get_product_id();  
      if ( has_term( 'special-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e special-flowers
         $order->update_status( 'wc-prepare' ); // your status here
         break;
      } else if ( has_term( 'cheap-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e cheap-flowers
         $order->update_status( 'wc-prepare' ); // your status here
         break;
      }
    }
}
或者,如果你想得到花式,你可以检查他们的购物车中是否有来自多只猫的物品

add_action( 'woocommerce_checkout_order_processed', 'custom_order_status_by_cat', 10, 3 );
function custom_order_status_by_cat( $order_id, $posted_data, $order ){
    $items = $order->get_items(); 
    foreach ( $items as $item ) {      
      $product_id = $item->get_product_id();  
      if ( has_term( 'special-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e special-flowers
         if ( has_term( 'cheap-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e cheap-flowers
            $order->update_status( 'wc-prepare' ); // your status here
            break;
         }
      }  
    }
}

同样,这是未经测试,但我相信它应该工作

谢谢大家的支持,解决了!我还有一个问题。当我添加您发送的代码时,个性化产品的订单会自动切换到wp prepare。但是,通过银行转账的个性化产品订单必须暂停。现在,银行转账下的订单自动切换到wp prepare。因此如果订单是个性化产品和银行转账,则应暂停,如果是个性化产品和其他付款方式,则应准备。我也希望你能在这个问题上给予帮助。