代码改变世界

wordpress woocommerce api 设置product_brand

2025-03-18 21:56  狼人:-)  阅读(30)  评论(0)    收藏  举报

https://woocommerce.com/document/managing-product-taxonomies/product-brands/

Brands REST API

The Brands REST API allows you to create, view, update, and delete individual, or a batch, of brands. The endpoint is /wp-json/wc/v1/products/brands which basically mimics /wp-json/wc/v1/products/categories. You can refer to the same documentation of product categories REST API.

In addition to /products/brands endpoints, the /products endpoints also updated to display brands in the response and check the JSON request for brands.

Examples

  • Retrieve all product brands:

    curl https://example.com/wp-json/wc/v2/products/brands -u consumer_key:consumer_secret
    
  • Create a product brand:

    curl -X POST https://example.com/wp-json/wc/v2/products/brands \
     -u consumer_key:consumer_secret \
     -H "Content-Type: application/json" \
     -d '{
     "name": "Apple",
     "image": {
       "src": "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Apple_logo_black.svg/768px-Apple_logo_black.svg.png"
      }
    }'
    
  • Delete a product brand:

    curl -X DELETE https://example.com/wp-json/wc/v2/products/brands/9?force=true -u consumer_key:consumer_secret
    
  • Set brands to a product:

     curl -X PUT https://example.com/wp-json/wc/v2/products/123 \
      -u consumer_key:consumer_secret \
      -H 'Content-Type: application/json' \
      -d '{"brands": [48, 49]}'
    

    Note: When setting a brand to a product the url needs to be products/123 where 123 is the id of the product you want to update.