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. MANDATORY
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. Options: default, products, subcategories and both. Default is default.
imageobjectImage data. See Product category - Image properties
menu_orderintegerMenu order, used to custom sort the resource.
countintegerNumber of published products for the resource. READ-ONLY

Product category - Image properties

AttributeTypeDescription
idintegerImage ID.
date_createddate-timeThe date the image was created, in the site's timezone. READ-ONLY
date_created_gmtdate-timeThe date the image was created, as GMT READ-ONLY
date_modifieddate-timeThe date the image was last modified, in the site's timezone. READ-ONLY
date_modified_gmtdate-timeThe date the image was last modified, as GMT. READ-ONLY
srcstringImage URL.
namestringImage name.
altstringImage alternative text.

Create a product category

This API helps you to create a new product category.

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

Example of how to create a product category:

curl -X POST https://example.com/wp-json/wc/v3/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/v3/products/categories/<id>
curl https://example.com/wp-json/wc/v3/products/categories/9 \
-u consumer_key:consumer_secret

List all product categories

This API lets you retrieve all product categories.

GET /wp-json/wc/v3/products/categories
curl https://example.com/wp-json/wc/v3/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. Default is view.
pageintegerCurrent page of the collection. Default is 1.
per_pageintegerMaximum number of items to be returned in result set. Default is 10.
searchstringLimit results to those matching a string.
excludearrayEnsure result set excludes specific ids.
includearrayLimit result set to specific ids.
orderstringOrder sort attribute ascending or descending. Options: asc and desc. Default is asc.
orderbystringSort collection by resource attribute. Options: id, include, name, slug, term_group, description and count. Default is name.
hide_emptybooleanWhether 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/v3/products/categories/<id>
curl -X PUT https://example.com/wp-json/wc/v3/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/v3/products/categories/<id>
curl -X DELETE https://example.com/wp-json/wc/v3/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/v3/products/categories/batch
curl -X POST https://example.com/wp-json/wc/v3/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
]
}'