2015-04-14 49 views
0

我需要按某些sku項目過濾訂單。這裏是我的代碼,其中IM過濾的狀態:如何按項目sku按順序過濾woocommerce api?

$params = array('status' => 'processing'); 
return $wc_api->get_orders($params); 

有回報的響應:

stdClass Object 
(
    [orders] => Array 
     (
      [0] => stdClass Object 
       (
        [id] => 30 
        [order_number] => 30 
        [status] => processing 
        [line_items] => Array 
         (
          [0] => stdClass Object 
           (
            [id] => 1 
            [subtotal] => 40.00 
            [subtotal_tax] => 0.00 
            [total] => 40.00 
            [total_tax] => 0.00 
            [price] => 40.00 
            [quantity] => 1 
            [tax_class] => 
            [name] => automobilis1 
            [product_id] => 4 
            [sku] => sku111111 
            [meta] => Array 
             (
             ) 

           ) 

         ) 

     ) 

) 

有DOC: https://github.com/kloon/WooCommerce-REST-API-Client-Library

如何篩選爲了在那裏的項目有SKU前。 123?

回答

0

WooCommerce REST API不提供sku過濾。

但是,您可以在接收到API後處理訂單列表。

像這樣:

$result = array(); 
$params = array('status' => 'processing'); 
$api_result = $wc_api->get_orders($params); 

foreach ($api_result->orders as $order) { 
    foreach ($order['line_items'] as $item) { 
     if ($item->sku == "123") { 
      $result[] = $order; 
      break; 
     } 
    } 
} 

return $result; 
+0

感謝它爲我工作:) – Haroldas