如何按商品 sku 过滤以订购 woocommerce api?
how to filter by item sku in order woocommerce api?
我需要按带有某些 sku 的商品过滤订单。这是我按状态过滤的代码:
$params = array( 'status' => 'processing' );
return $wc_api->get_orders($params);
有 return 的响应:
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
(
)
)
)
)
)
有文档:
https://github.com/kloon/WooCommerce-REST-API-Client-Library
如何过滤商品有 sku ex 的顺序。 123?
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;
我需要按带有某些 sku 的商品过滤订单。这是我按状态过滤的代码:
$params = array( 'status' => 'processing' );
return $wc_api->get_orders($params);
有 return 的响应:
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
(
)
)
)
)
)
有文档: https://github.com/kloon/WooCommerce-REST-API-Client-Library
如何过滤商品有 sku ex 的顺序。 123?
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;