Skip to main content

Product categories

The product categories API allows you to create, view, update, and delete individual, or a batch, of categories.

Product category properties

AttributeTypeDescription
idintegerUnique identifier for the resource. READ-ONLY
namestringCategory name. REQUIRED
slugstringAn alphanumeric identifier for the resource unique to its type.
parentintegerThe id for the parent of the resource.
descriptionstringHTML description of the resource.
displaystringCategory archive display type. Default is default. Options: default, products, subcategories and both
imagearrayImage data. See Category Image properties
menu_orderintegerMenu order, used to custom sort the resource.
countintegerNumber of published products for the resource. READ-ONLY

Category Image properties

AttributeTypeDescription
idintegerImage ID (attachment ID). In write-mode used to attach pre-existing images.
date_createddate-timeThe date the image was created, in the site's timezone. READ-ONLY
date_modifieddate-timeThe date the image was last modified, in the site's timezone. READ-ONLY
srcstringImage URL. In write-mode used to upload new images.
titlestringImage name.
altstringImage alternative text.

Create a product category

This API helps you to create a new product category.

POST /wp-json/wc/v1/products/categories

Example of how to create a product category:

curl -X POST https://example.com/wp-json/wc/v1/products/categories \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "Clothing",
"image": {
"src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
}
}'

Retrieve a product category

This API lets you retrieve a product category by ID.

GET /wp-json/wc/v1/products/categories/<id>
curl https://example.com/wp-json/wc/v1/products/categories/9 \
-u consumer_key:consumer_secret

List all product categories

This API lets you retrieve all product categories.

GET /wp-json/wc/v1/products/categories
curl https://example.com/wp-json/wc/v1/products/categories \
-u consumer_key:consumer_secret

Available parameters

ParameterTypeDescription
contextstringScope under which the request is made; determines fields present in response. Options: view and edit.
pageintegerCurrent page of the collection.
per_pageintegerMaximum number of items to be returned in result set.
searchstringLimit results to those matching a string.
excludestringEnsure result set excludes specific ids.
includestringLimit result set to specific ids.
orderstringOrder sort attribute ascending or descending. Default is asc. Options: asc and desc.
orderbystringSort collection by object attribute. Default is name. Options: id, include, name, slug, term_group, description and count.
hide_emptyboolWhether to hide resources not assigned to any products. Default is false.
parentintegerLimit result set to resources assigned to a specific parent.
productintegerLimit result set to resources assigned to a specific product.
slugstringLimit result set to resources with a specific slug.

Update a product category

This API lets you make changes to a product category.

PUT /wp-json/wc/v1/products/categories/<id>
curl -X PUT https://example.com/wp-json/wc/v1/products/categories/9 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"description": "All kinds of clothes."
}'

Delete a product category

This API helps you delete a product category.

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

Available parameters

ParameterTypeDescription
forcestringRequired to be true, as resource does not support trashing.

Batch update product categories

This API helps you to batch create, update and delete multiple product categories.

note

Note: By default it's limited to up to 100 objects to be created, updated or deleted.

POST /wp-json/wc/v1/products/categories/batch
curl -X POST https://example.com/wp-json/wc/v1/products/categories/batch \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"create": [
{
"name": "Albums"
},
{
"name": "Clothing"
}
],
"update": [
{
"id": 10,
"description": "Nice hoodies"
}
],
"delete": [
11,
12
]
}'