跳到主要内容
将当前页面内容以 Markdown 格式复制到剪贴板

产品属性项

产品属性术语 API 允许您创建、查看、更新和删除单个或批量属性术语。

产品属性术语属性

属性类型描述
idinteger资源的唯一标识符。只读
namestring术语名称。必填
slugstring用于标识资源的字母数字标识符,该标识符在资源类型中是唯一的。
descriptionstring资源的 HTML 描述。
menu_orderinteger菜单顺序,用于自定义排序资源。
countinteger该资源已发布的产品的数量。只读

创建一个属性术语

此 API 可帮助您创建新的产品属性术语。

POST /wp-json/wc/v3/products/attributes/<attribute_id>/terms
curl -X POST https://example.com/wp-json/wc/v3/products/attributes/2/terms \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "XXS"
}'

获取属性项目

此 API 允许您通过编号检索产品的属性项目。

GET /wp-json/wc/v3/products/attributes/<attribute_id>/terms/<id>
curl https://example.com/wp-json/wc/v3/products/attributes/2/terms/23 \
-u consumer_key:consumer_secret

列出所有属性条款

此 API 允许您从产品属性中检索所有条款。

GET /wp-json/wc/v3/products/attributes/<attribute_id>/terms
curl https://example.com/wp-json/wc/v3/products/attributes/2/terms \
-u consumer_key:consumer_secret

Available parameters

ParameterTypeDescription
contextstringScope under which the request is made; determines fields present in response. Options: view and edit. Default is view.
pageintegerCurrent page of the collection. Default is 1.
per_pageintegerMaximum number of items to be returned in result set. Default is 10.
searchstringLimit results to those matching a string.
excludearrayEnsure result set excludes specific ids.
includearrayLimit result set to specific ids.
orderstringOrder sort attribute ascending or descending. Options: asc and desc. Default is asc.
orderbystringSort collection by resource attribute. Options: id, include, name, slug, term_group, description and count. Default is name.
hide_emptybooleanWhether to hide resources not assigned to any products. Default is false.
parentintegerLimit result set to resources assigned to a specific parent.
productintegerLimit result set to resources assigned to a specific product.
slugstringLimit result set to resources with a specific slug.

Update an attribute term

This API lets you make changes to a product attribute term.

PUT /wp-json/wc/v3/products/attributes/<attribute_id>/terms/<id>
curl -X PUT https://example.com/wp-json/wc/v3/products/attributes/2/terms/23 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "XXS"
}'

删除一个属性项目

这个 API 可以帮助您删除一个产品属性项目。

DELETE /wp-json/wc/v3/products/attributes/<attribute_id>/terms/<id>
curl -X DELETE https://example.com/wp-json/wc/v3/products/attributes/2/terms/23?force=true \
-u consumer_key:consumer_secret

可用参数

参数类型描述
force字符串必须为 true,因为资源不支持放入回收站。

批量更新属性项

此 API 可以帮助您批量创建、更新和删除多个产品属性项。

备注

注意:默认情况下,限制为最多可以创建、更新或删除 100 个对象。

POST /wp-json/wc/v3/products/attributes/<attribute_id>/terms/batch
curl -X POST https://example.com/wp-json/wc/v3/products/attributes/<attribute_id>/terms/batch \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"create": [
{
"name": "XXS"
},
{
"name": "S"
}
],
"update": [
{
"id": 19,
"menu_order": 6
}
],
"delete": [
21,
20
]
}'