WooCommerce API Products

The WooCommerce API allows you to manage products in your store, including creating, updating, retrieving, and deleting products. This guide covers the essential operations and properties for working with products effectively.

What can you do with Products in the WooCommerce API?

The most common operations people perform on products using the WooCommerce API.

Action HTTP Method Endpoint
Create a Product
POST /products
List All Products
GET /products
Retrieve a Product
GET /products/{productId}
Update a Product
PUT /products/{productId}
Delete a Product
DELETE /products/{productId}

Products are the core of your WooCommerce store, representing the items you sell. This API allows you to manage all aspects of your products, from creation to deletion.

Products are identified by a unique integer ID, which is used in API requests to specify the product.

To create a product, you need to provide at least the product name. Other fields such as price, description, and categories are optional but recommended.

You can search for products using various query parameters such as search for text matching, sku for specific SKU, and category for filtering by category ID.

Properties of a Product

The properties section provides detailed information about the fields available for products. These properties are crucial for understanding how to manage products effectively. Show all properties Only show essential properties

Field Name Type Short Description
id integer Unique identifier for the product.
name string Product name.
price string Current product price. read-only
regular_price string Regular product price.
sale_price string Product sale price.
sku string Unique identifier for the product.
stock_quantity integer Stock quantity.
status string Product status (post status). Options: draft, pending, private and publish.
categories array List of categories.
tags array List of tags.
images array List of product images.
date_created datetime The date the product was created, in the site's timezone. read-only
slug string Product slug.
permalink string Product URL. read-only
date_created_gmt datetime The date the product was created, as GMT. read-only
date_modified datetime The date the product was last modified, in the site's timezone. read-only
date_modified_gmt datetime The date the product was last modified, as GMT. read-only
type string Product type. Options: simple, grouped, external and variable.
featured boolean Featured product. Default is false.
catalog_visibility string Catalog visibility. Options: visible, catalog, search and hidden.
description string Product description.
short_description string Product short description.
date_on_sale_from datetime Start date of sale price, in the site's timezone.
date_on_sale_from_gmt datetime Start date of sale price, as GMT.
date_on_sale_to datetime End date of sale price, in the site's timezone.
date_on_sale_to_gmt datetime End date of sale price, as GMT.
price_html string Price formatted in HTML. read-only
on_sale boolean Shows if the product is on sale. read-only
purchasable boolean Shows if the product can be bought. read-only
total_sales integer Amount of sales. read-only
virtual boolean If the product is virtual. Default is false.
downloadable boolean If the product is downloadable. Default is false.
downloads array List of downloadable files.
download_limit integer Number of times downloadable files can be downloaded after purchase.
download_expiry integer Number of days until access to downloadable files expires.
external_url string Product external URL. Only for external products.
button_text string Product external button text. Only for external products.
tax_status string Tax status. Options: taxable, shipping and none.
tax_class string Tax class.
manage_stock boolean Stock management at product level.
stock_status string Controls the stock status of the product. Options: instock, outofstock, onbackorder.
backorders string If managing stock, this controls if backorders are allowed.
backorders_allowed boolean Shows if backorders are allowed. read-only
backordered boolean Shows if the product is on backordered. read-only
sold_individually boolean Allow one item to be bought in a single order.
weight string Product weight.
dimensions object Product dimensions.
shipping_required boolean Shows if the product need to be shipped. read-only
shipping_taxable boolean Shows whether or not the product shipping is taxable. read-only
shipping_class string Shipping class slug.
shipping_class_id integer Shipping class ID.
reviews_allowed boolean Allow reviews.
average_rating string Reviews average rating. read-only
rating_count integer Amount of reviews that the product have. read-only
related_ids array List of related products IDs. read-only
upsell_ids array List of up-sell products IDs.
cross_sell_ids array List of cross-sell products IDs.
parent_id integer Product parent ID.
purchase_note string Optional note to send the customer after purchase.
default_attributes array List of default attributes.
variations array List of variations IDs. read-only
grouped_products array List of grouped products ID.
menu_order integer Menu order, used to custom sort products.
meta_data array Meta data properties.

Filtering and Query Parameters

The WooCommerce API provides extensive filtering options to help you retrieve the exact products you need.

Parameter Type Description Example
search string Limit results to those matching a string. search=shirt
after string Limit response to resources published after a given date. after=2023-01-01T00:00:00
before string Limit response to resources published before a given date. before=2023-12-31T23:59:59
sku string Limit result set to products with a specific SKU. sku=12345
category string Limit result set to products assigned a specific category ID. category=10
tag string Limit result set to products assigned a specific tag ID. tag=5
min_price string Limit result set to products based on a minimum price. min_price=20
max_price string Limit result set to products based on a maximum price. max_price=100

What to watch out for

When working with the WooCommerce Products API, there are a few common pitfalls to be aware of to ensure smooth integration.

Immutable Fields

Certain fields like id and date_created are read-only and cannot be modified once set.

Stock Management

Ensure manage_stock is set correctly when updating stock-related fields to avoid inconsistencies.

Product Variations

Product variations have their own set of properties and must be managed separately from the main product.

Frequently Asked Questions

Below are some frequently asked questions about the WooCommerce Products API and how to manage products effectively.

How do I find a product by SKU in the WooCommerce API?

To find a product by SKU, use the sku query parameter in the GET /products endpoint. For example, /products?sku=12345 will return the product with the specified SKU.

What happens when I update a product in WooCommerce?

When you update a product using the PUT /products/{productId} endpoint, the specified fields in the request body will be updated. Fields not included in the request will remain unchanged.

Can I delete a product that has variations in WooCommerce?

Yes, you can delete a product with variations using the DELETE /products/{productId} endpoint. However, this will also delete all associated variations.

What's the difference between regular price and sale price in WooCommerce?

The regular_price is the standard price of the product, while the sale_price is a discounted price that can be set for promotional periods. The sale price is only active during the specified sale dates.

How do I handle downloadable products in WooCommerce?

For downloadable products, set downloadable to true and provide a list of downloadable files in the downloads field. You can also specify download_limit and download_expiry for additional control.