我需要带有一些sku的项目的过滤器订单。这是我的代码,其中我按状态过滤:
$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 ex的顺序。 123?
答案 0 :(得分:1)
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;