产品集合数据 API
此接口允许您获取产品集合的聚合数据,例如,在一个产品集合中获取最高和最低价格(忽略分页)。 这由产品筛选小工具中的块使用,因为计数基于正在查看的产品目录。
GET /products/collection-data
GET /products/collection-data?calculate_price_range=true
GET /products/collection-data?calculate_attribute_counts[0][query_type]=or&calculate_attribute_counts[0][taxonomy]=pa_color
GET /products/collection-data?calculate_rating_counts=true
GET /products/collection-data?calculate_taxonomy_counts=product_cat
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
calculate_price_range | bool | 否 | 返回产品集合的最低和最高价格。 如果为 false,则仅返回 null。 |
calculate_attribute_counts | object | 否 | 返回一组属性分类的属性计数,您可以通过此参数传递这些分类。 每个分类应以包含键 "taxonomy" 和 "query_type" 的对象形式提供。 如果为空,则返回 null。 |
calculate_rating_counts | bool | 否 | 返回具有特定平均评级的产品的计数,范围为 1-5。 如果为 false,则仅返回 null。 |
calculate_stock_status_counts | bool | 否 | 返回具有每种库存状态(在库存中、缺货、延期交货)的产品计数。 如果为 false,则仅返回 null。 |
calculate_taxonomy_counts | array | 否 | 返回一组分类的分类计数,您可以通过此参数传递这些分类。 每个分类应以分类名称字符串的形式提供。 如果为空,则返回 null。 |
除了上述属性之外,还支持所有产品列表属性。 这允许您获取特定产品子集的数据。 请参阅 产品 API 列表产品部分,以获取完整列表。
curl "https://example-store.com/wp-json/wc/store/v1/products/collection-data?calculate_price_range=true&calculate_attribute_counts=pa_size,pa_color&calculate_rating_counts=true&calculate_taxonomy_counts=product_cat,product_tag"
{
"price_range": [
"currency_minor_unit": 2,
"min_price": "0",
"max_price": "9000",
"currency_code": "USD",
"currency_decimal_separator": ".",
"currency_minor_unit": 2,
"currency_prefix": "$",
"currency_suffix": "",
"currency_symbol": "$",
"currency_thousand_separator": ",",
],
"attribute_counts": [
{
"term": 22,
"count": 4
},
{
"term": 23,
"count": 3
},
{
"term": 24,
"count": 4
}
],
"rating_counts": [
{
"rating": 3,
"count": 1
},
{
"rating": 4,
"count": 1
}
],
"taxonomy_counts": [
{
"term": 25,
"count": 8
},
{
"term": 26,
"count": 6
},
{
"term": 27,
"count": 2
}
]
}