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

产品配送类型

产品配送类型 API 允许您创建、查看、更新和删除单个或批量配送类型。

产品配送类型属性

属性类型描述
idinteger该资源的唯一标识符。只读
namestring配送类型名称。必填
slugstring用于该资源类型的字母数字标识符。
descriptionstring该资源的 HTML 描述。
countinteger该资源已发布的产品的数量。只读

创建一个配送类型

此 API 可帮助您创建新的产品配送类型。

POST /wp-json/wc/v3/products/shipping_classes

创建产品配送类型的例子:

curl -X POST https://example.com/wp-json/wc/v3/products/shipping_classes \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "Priority"
}'

获取配送类型

此 API 允许您通过编号获取产品的配送类型。

GET /wp-json/wc/v3/products/shipping_classes/<id>
curl https://example.com/wp-json/wc/v3/products/shipping_classes/32 \
-u consumer_key:consumer_secret

列出所有配送类型

此 API 允许您检索所有产品的配送类型。

GET /wp-json/wc/v3/products/shipping_classes
curl https://example.com/wp-json/wc/v3/products/shipping_classes \
-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.
offsetintegerOffset the result set by a specific number of items.
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.
productintegerLimit result set to resources assigned to a specific product.
slugstringLimit result set to resources with a specific slug.

Update a shipping class

This API lets you make changes to a product shipping class.

PUT /wp-json/wc/v3/products/shipping_classes/<id>
curl -X PUT https://example.com/wp-json/wc/v3/products/shipping_classes/32 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"description": "Priority mail."
}'

删除一个配送类型

这个 API 可以帮助您删除产品的配送类型。

DELETE /wp-json/wc/v3/products/shipping_classes/<id>
curl -X DELETE https://example.com/wp-json/wc/v3/products/shipping_classes/32?force=true \
-u consumer_key:consumer_secret

可用参数

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

批量更新配送类型

此 API 可以帮助您批量创建、更新和删除多个产品的配送类型。

备注

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

POST /wp-json/wc/v3/products/shipping_classes/batch
curl -X POST https://example.com/wp-json/wc/v3/products/shipping_classes/batch \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"create": [
{
"name": "Small items"
},
{
"name": "Large items"
}
],
"update": [
{
"id": 33,
"description": "Express shipping"
}
],
"delete": [
32
]
}'