7 KiB
Product - Attribute Terms
This section lists all API endpoints that can be used to create, edit or otherwise manipulate product attribute terms.
Product Attribute Properties
| Attribute | Type | Description |
|---|---|---|
id |
integer | Term ID (term ID) read-only |
name |
string | Term name required |
slug |
string | Term slug |
count |
integer | Shows the quantity of products in this term read-only |
Create a Product Attribute Term
This API helps you to create a new product attribute term.
HTTP Request
/wc-api/v3/products/attributes/<attribute_id>/terms
curl -X POST https://example.com/wc-api/v3/products/attributes/1/terms \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"product_attribute_term": {
"name": "Black"
}
}'
var data = {
product_attribute_term: {
name: 'Black'
}
};
WooCommerce.post('products/attributes/1/terms', data, function(err, data, res) {
console.log(res);
});
<?php
$data = [
'product_attribute_term' => [
'name' => 'Black'
]
];
print_r($woocommerce->post('products/attributes/1/terms', $data));
?>
data = {
"product_attribute_term": {
"name": "Black"
}
}
print(wcapi.post("products/attributes/1/terms", data).json())
data = {
product_attribute_term: {
name: "Black"
}
}
woocommerce.post("products/attributes/1/terms", data).parsed_response
JSON response example:
{
"product_attribute_term": {
"id": 18,
"name": "Black",
"slug": "black",
"count": 0
}
}
View a Product Attribute Term
This API lets you retrieve a product attribute term by ID.
/wc-api/v3/products/attributes/<attribute_id>/terms/<id>
curl https://example.com/wc-api/v3/products/attributes/1/terms/18 \
-u consumer_key:consumer_secret
WooCommerce.get('products/attributes/1/terms/18', function(err, data, res) {
console.log(res);
});
<?php print_r($woocommerce->get('products/attributes/1/terms/18')); ?>
print(wcapi.get("products/attributes/1/terms/18").json())
woocommerce.get("products/attributes/1/terms/18").parsed_response
JSON response example:
{
"product_attribute_term": {
"id": 18,
"name": "Black",
"slug": "black",
"count": 5
}
}
View List of Product Attribute Terms
This API lets you retrieve all terms from a product attribute.
/wc-api/v3/products/attributes/<attribute_id>/terms
curl https://example.com/wc-api/v3/products/attributes/1/terms \
-u consumer_key:consumer_secret
WooCommerce.get('products/attributes/1/terms', function(err, data, res) {
console.log(res);
});
<?php print_r($woocommerce->get('products/attributes/1/terms')); ?>
print(wcapi.get("products/attributes/1/terms").json())
woocommerce.get("products/attributes/1/terms").parsed_response
JSON response example:
{
"product_attribute_terms": [
{
"id": 18,
"slug": "black",
"name": "Black",
"count": 5
},
{
"id": 20,
"slug": "blue",
"name": "Blue",
"count": 4
},
{
"id": 19,
"slug": "green",
"name": "Green",
"count": 4
},
{
"id": 24,
"slug": "pink",
"name": "Pink",
"count": 3
},
{
"id": 22,
"slug": "red",
"name": "Red",
"count": 3
},
{
"id": 21,
"slug": "white",
"name": "White",
"count": 3
},
{
"id": 23,
"slug": "yellow",
"name": "Yellow",
"count": 3
}
]
}
Update a Product Attribute Term
This API lets you make changes to a product attribute term.
HTTP Request
/wc-api/v3/products/attributes/<attribute_id>/terms/<id>
curl -X PUT https://example.com/wc-api/v3/products/attributes/1/terms/18 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"product_attribute_term": {
"name": "BLACK"
}
}'
var data = {
product_attribute_term: {
name: 'BLACK'
}
};
WooCommerce.put('products/attributes/1/terms/18', data, function(err, data, res) {
console.log(res);
});
<?php
$data = [
'product_attribute_term' => [
'name' => 'BLACK'
]
];
print_r($woocommerce->put('products/attributes/1/terms/18', $data));
?>
data = {
"product_attribute_term": {
"name": "BLACK"
}
}
print(wcapi.put("products/attributes/1/terms/18", data).json())
data = {
product_attribute_term: {
name: "BLACK"
}
}
woocommerce.put("products/attributes/1/terms/18", data).parsed_response
JSON response example:
{
"product_attribute_term": {
"id": 18,
"name": "BLACK",
"slug": "black",
"count": 5
}
}
Delete a Product Attribute Term
This API helps you delete a product attribute term.
HTTP Request
/wc-api/v3/products/attributes/<attribute_id>/terms/<id>
curl -X DELETE https://example.com/wc-api/v3/products/attributes/1/terms/18 \
-u consumer_key:consumer_secret
WooCommerce.delete('products/attributes/1/terms/18', function(err, data, res) {
console.log(res);
});
<?php print_r($woocommerce->delete('products/attributes/1/terms/18')); ?>
print(wcapi.delete("products/attributes/1/terms/18").json())
woocommerce.delete("products/attributes/1/terms/18").parsed_response
JSON response example:
{
"message": "Deleted product_attribute_term"
}