跳转到主要内容

产品分类 API

列出产品分类

GET /products/categories
属性 类型 是否必需 描述
context 字符串 否 发起请求的范围;决定响应中包含的字段。
page 整数 否 集合的当前页。默认为 1。
per_page 整数 否 结果集中返回的最大项目数。默认为无限制。允许 0 到 100 之间的值。
search 字符串 否 将结果限制为匹配特定字符串的项目。
exclude 数组 否 确保结果集排除特定的 ID。
include 数组 否 将结果集限制为特定的 ID。
order 字符串 否 升序或降序排序。允许的值:asc, desc。默认为 asc。
orderby 字符串 否 按术语属性排序。允许的值:name, slug, count。默认为 name。
hide_empty 布尔值 否 如果为 true,则不返回空术语。默认为 true。
parent 整数 否 将结果限制为具有特定父级 ID 的项目。
curl "https://example-store.com/wp-json/wc/store/v1/products/categories"

示例响应:

[
	{
		"id": 16,
		"name": "Clothing",
		"slug": "clothing",
		"description": "This is the clothing category.",
		"parent": 0,
		"count": 11,
		"image": {
			"id": 55,
			"src": "https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1.jpg",
			"thumbnail": "https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-324x324.jpg",
			"srcset": "https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1.jpg 800w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-324x324.jpg 324w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-100x100.jpg 100w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-416x416.jpg 416w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-300x300.jpg 300w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-150x150.jpg 150w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-768x768.jpg 768w",
			"sizes": "(max-width: 800px) 100vw, 800px",
			"name": "t-shirt-with-logo-1.jpg",
			"alt": ""
		},
		"review_count": 2,
		"permalink": "https://store.local/product-category/clothing/"
	},
	{
		"id": 21,
		"name": "Decor",
		"slug": "decor",
		"description": "",
		"parent": 0,
		"count": 1,
		"image": null,
		"review_count": 1,
		"permalink": "https://store.local/product-category/decor/"
	}
]

产品分类

获取单个分类。

GET /products/categories/:id
分类 类型 必填 描述
id 整数 是 要检索的分类的 ID。
curl "https://example-store.com/wp-json/wc/store/v1/products/categories/1"

示例回复:

{
	"id": 1,
	"name": "Decor",
	"slug": "decor",
	"description": "",
	"parent": 0,
	"count": 1,
	"image": null,
	"review_count": 1,
	"permalink": "https://store.local/product-category/decor/"
}