产品标签 #
产品标签 API 允许您创建、查看、更新和删除单个或批量产品标签。
产品标签属性
| 属性 | 类型 | 描述 |
|---|---|---|
id |
整数 | 资源的唯一标识符。只读 |
name |
字符串 | 标签名称。必需 |
slug |
字符串 | 资源在其类型中唯一的字母数字标识符。 |
description |
字符串 | 资源的 HTML 描述。 |
count |
整数 | 资源关联的已发布产品数量。只读 |
创建产品标签
此 API 可帮助您创建新的产品标签。
HTTP 请求
POST
/wp-json/wc/v1/products/tags
如何创建产品标签的示例:
curl -X POST https://example.com/wp-json/wc/v1/products/tags \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "Leather Shoes"
}'
const data = {
name: "Leather Shoes"
};
WooCommerce.post("products/tags", data)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
<?php
$data = [
'name' => 'Leather Shoes'
];
print_r($woocommerce->post('products/tags', $data));
?>
data = {
"name": "Leather Shoes"
}
print(wcapi.post("products/tags", data).json())
data = {
name: "Leather Shoes"
}
woocommerce.post("products/tags", data).parsed_response
JSON 响应示例:
{
"id": 34,
"name": "Leather Shoes",
"slug": "leather-shoes",
"description": "",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/34"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
}
获取商品标签
此 API 允许您通过 ID 检索商品标签。
GET
/wp-json/wc/v1/products/tags/<id>
curl https://example.com/wp-json/wc/v1/products/tags/34 \
-u consumer_key:consumer_secret
WooCommerce.get("products/tags/34")
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
<?php print_r($woocommerce->get('products/tags/34')); ?>
print(wcapi.get("products/tags/34").json())
woocommerce.get("products/tags/34").parsed_response
JSON 响应示例:
{
"id": 34,
"name": "Leather Shoes",
"slug": "leather-shoes",
"description": "",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/34"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
}
列出所有产品标签
此 API 允许您检索所有产品标签。
GET
/wp-json/wc/v1/products/tags
curl https://example.com/wp-json/wc/v1/products/tags \
-u consumer_key:consumer_secret
WooCommerce.get("products/tags")
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
<?php print_r($woocommerce->get('products/tags')); ?>
print(wcapi.get("products/tags").json())
woocommerce.get("products/tags").parsed_response
JSON 响应示例:
[
{
"id": 34,
"name": "Leather Shoes",
"slug": "leather-shoes",
"description": "",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/34"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
},
{
"id": 35,
"name": "Oxford Shoes",
"slug": "oxford-shoes",
"description": "",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/35"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
}
]
Available parameters
| Parameter | Type | Description |
|---|---|---|
context |
string | Scope under which the request is made; determines fields present in response. Options: view and edit. |
page |
integer | Current page of the collection. |
per_page |
integer | Maximum number of items to be returned in result set. |
search |
string | Limit results to those matching a string. |
exclude |
string | Ensure result set excludes specific ids. |
include |
string | Limit result set to specific ids. |
order |
string | Order sort attribute ascending or descending. Default is asc. Options: asc and desc. |
orderby |
string | Sort collection by object attribute. Default is name. Options: id, include, name, slug, term_group, description and count. |
hide_empty |
bool | Whether to hide resources not assigned to any products. Default is false. |
product |
integer | Limit result set to resources assigned to a specific product. |
slug |
string | Limit result set to resources with a specific slug. |
更新产品标签
此 API 允许您修改产品标签。
HTTP 请求
PUT
/wp-json/wc/v1/products/tags/<id>
curl -X PUT https://example.com/wp-json/wc/v1/products/tags/34 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"description": "Genuine leather."
}'
const data = {
description: "Genuine leather."
};
WooCommerce.put("products/tags/34", data)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
<?php
$data = [
'description': 'Genuine leather.'
];
print_r($woocommerce->put('products/tags/34', $data));
?>
data = {
"description": "Genuine leather."
}
print(wcapi.put("products/tags/34", data).json())
data = {
description: "Genuine leather."
}
woocommerce.put("products/tags/34", data).parsed_response
JSON 响应示例:
{
"id": 34,
"name": "Leather Shoes",
"slug": "leather-shoes",
"description": "Genuine leather.",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/34"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
}
删除产品标签
此 API 可帮助您删除产品标签。
HTTP 请求
DELETE
/wp-json/wc/v1/products/tags/<id>
curl -X DELETE https://example.com/wp-json/wc/v1/products/tags/34?force=true \
-u consumer_key:consumer_secret
WooCommerce.delete("products/tags/34", {
force: true
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
<?php print_r($woocommerce->delete('products/tags/34', ['force' => true])); ?>
print(wcapi.delete("products/tags/34", params={"force": True}).json())
woocommerce.delete("products/tags/34", force: true).parsed_response
JSON 响应示例:
{
"id": 34,
"name": "Leather Shoes",
"slug": "leather-shoes",
"description": "Genuine leather.",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/34"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
}
Available parameters
| Parameter | Type | Description |
|---|---|---|
force |
string | Required to be true, as resource does not support trashing. |
批量更新产品标签
此 API 可帮助您批量创建、更新和删除多个产品标签。
HTTP 请求
POST
/wp-json/wc/v1/products/tags/batch
curl -X POST https://example.com//wp-json/wc/v1/products/tags/batch \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"create": [
{
"name": "Round toe"
},
{
"name": "Flat"
}
],
"update": [
{
"id": 34,
"description": "Genuine leather."
}
],
"delete": [
35
]
}'
const data = {
create: [
{
name: "Round toe"
},
{
name: "Flat"
}
],
update: [
{
id: 34,
description: "Genuine leather."
}
],
delete: [
35
]
};
WooCommerce.post("products/tags/batch", data)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
<?php
$data = [
'create' => [
[
'name' => 'Round toe'
],
[
'name' => 'Flat'
]
],
'update' => [
[
'id' => 34,
'description' => 'Genuine leather.'
]
],
'delete' => [
35
]
];
print_r($woocommerce->post('products/tags/batch', $data));
?>
data = {
"create": [
{
"name": "Round toe"
},
{
"name": "Flat"
}
],
"update": [
{
"id": 34,
"description": "Genuine leather."
}
],
"delete": [
35
]
}
print(wcapi.post("products/tags/batch", data).json())
data = {
create: [
{
name: "Round toe"
},
{
name: "Flat"
}
],
update: [
{
id: 34,
description: "Genuine leather."
}
],
delete: [
35
]
}
woocommerce.post("products/tags/batch", data).parsed_response
JSON 响应示例:
{
"create": [
{
"id": 36,
"name": "Round toe",
"slug": "round-toe",
"description": "",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/36"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
},
{
"id": 37,
"name": "Flat",
"slug": "flat",
"description": "",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/37"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
}
],
"update": [
{
"id": 34,
"name": "Leather Shoes",
"slug": "leather-shoes",
"description": "Genuine leather.",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/34"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
}
],
"delete": [
{
"id": 35,
"name": "Oxford Shoes",
"slug": "oxford-shoes",
"description": "",
"count": 0,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags/35"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/products/tags"
}
]
}
}
]
}
这篇文档对你有帮助吗?
谢谢你的反馈!