2017-03-03 6 views

答えて

0
function mysite_hold($order_id) { 

    $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('completed'); //change your status here 
    } 
} 
add_action('woocommerce_order_status_on-hold', 'mysite_hold'); 

//You may need to store your backorder info like below 

wc_add_order_item_meta($item_id, 'Backordered', $qty - max(0, $product->get_total_stock())); 

ここ

+0

ありがとうございます。 しかし、この行にはエラーが表示されます: wc_add_order_item_meta($ item_id、 'Backordered'、$ qty-max(0、$ product-> get_total_stock())); –

+0

woocommerceで注文の詳細を取得するには? 注文に販売価格が含まれている場合は、注文ステータスを変更したい –

2

Updated compatibility for woocommerce 3+

このスニペットを試してみてくださいが、この順序は、「保留」のステータスを持っている場合は、注文状況を変更しますwoocommerce_thankyouアクションフックに引っかけカスタム関数であるにバックオーダー製品がある場合はです。

には、という新しいステータススラッグが設定されています。ここで

は(コードがよくコメントしている)そのカスタム関数次のとおりです。

add_action('woocommerce_thankyou', 'change_paid_backorders_status', 10, 1); 
function change_paid_backorders_status($order_id) { 

    if (! $order_id) 
     return; 

    // HERE set your new status SLUG for paid back orders <== <== <== <== <== <== <== 
    $new_status = 'completed'; 

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

    // ONLY for "on-hold" ORDERS Status 
    if (! $order->has_status('on-hold')) 
     return; 

    // Iterating through each item in the order 
    foreach ($order->get_items() as $item_values) { 

     // Get a an instance of product object related to the order item 
     product = version_compare(WC_VERSION, '3.0', '<') ? wc_get_product($item_values['product_id']); : $cart_item->get_product(); 

     // Check if the product is on backorder 
     if($product->is_on_backorder()){ 
      // Change this order status 
      $order->update_status($new_status); 
      break; // Stop the loop 
     } 
    } 
} 

コードは、任意のプラグインファイルでも、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルになりますか。

このコードはテスト済みであり、動作します。