WooCommerce REST API 文档

title: "产品 - 属性术语 #" post_status: publish comment_status: open taxonomy: category: - woocommerce-rest-api post_tag: - V3 - Includes - Source


产品 - 属性术语

本节列出了所有可用于创建、编辑或以其他方式操作产品属性术语的 API 端点。

产品属性特性

属性 类型 描述
id integer 术语 ID (term ID) 只读
name string 术语名称 必需
slug string 术语别名
count integer 显示此术语下的产品数量 只读

创建产品属性术语

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

HTTP 请求

POST
/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 响应示例:

{
  "product_attribute_term": {
    "id": 18,
    "name": "Black",
    "slug": "black",
    "count": 0
  }
}

查看产品属性术语

此 API 允许您通过 ID 检索产品属性术语。

GET
/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 响应示例:

{
  "product_attribute_term": {
    "id": 18,
    "name": "Black",
    "slug": "black",
    "count": 5
  }
}

查看产品属性术语列表

此 API 允许您检索产品属性的所有术语。

GET
/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 响应示例:

{
  "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
    }
  ]
}

更新产品属性术语

此 API 允许您修改产品属性术语。

HTTP 请求

PUT
/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 响应示例:

{
  "product_attribute_term": {
    "id": 18,
    "name": "BLACK",
    "slug": "black",
    "count": 5
  }
}

删除产品属性术语

此 API 可帮助您删除产品属性术语。

HTTP 请求

DELETE
/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 响应示例:

{
  "message": "Deleted product_attribute_term"
}