Skip to main content

Coupons

The coupons API allows you to create, view, update, and delete individual, or a batch, of coupon codes.

Coupon properties

AttributeTypeDescription
idintegerUnique identifier for the object. READ-ONLY
codestringCoupon code. MANDATORY
date_createddate-timeThe date the coupon was created, in the site's timezone. READ-ONLY
date_modifieddate-timeThe date the coupon was last modified, in the site's timezone. READ-ONLY
descriptionstringCoupon description.
discount_typestringDetermines the type of discount that will be applied. Options: fixed_cart, percent, fixed_product and percent_product. Default: fixed_cart.
amountstringThe amount of discount.
expiry_datestringUTC DateTime when the coupon expires.
usage_countintegerNumber of times the coupon has been used already. READ-ONLY
individual_usebooleanWhether coupon can only be used individually.
product_idsarrayList of product ID's the coupon can be used on.
exclude_product_idsarrayList of product ID's the coupon cannot be used on.
usage_limitintegerHow many times the coupon can be used.
usage_limit_per_userintegerHow many times the coupon can be used per customer.
limit_usage_to_x_itemsintegerMax number of items in the cart the coupon can be applied to.
free_shippingbooleanDefine if can be applied for free shipping.
product_categoriesarrayList of category ID's the coupon applies to.
excluded_product_categoriesarrayList of category ID's the coupon does not apply to.
exclude_sale_itemsbooleanDefine if should not apply when have sale items.
minimum_amountstringMinimum order amount that needs to be in the cart before coupon applies.
maximum_amountstringMaximum order amount allowed when using the coupon.
email_restrictionsarrayList of email addresses that can use this coupon.
used_byarrayList of user IDs who have used the coupon. READ-ONLY

Create a coupon

This API helps you to create a new coupon.

POST /wp-json/wc/v1/coupons
curl -X POST https://example.com/wp-json/wc/v1/coupons \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"code": "10off",
"discount_type": "percent",
"amount": 10,
"individual_use": true,
"exclude_sale_items": true,
"minimum_amount": "100.00"
}'

Retrieve a coupon

This API lets you retrieve and view a specific coupon by ID.

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

List all coupons

This API helps you to list all the coupons that have been created.

GET /wp-json/wc/v1/coupons
curl https://example.com/wp-json/wc/v1/coupons \
-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.
afterstringLimit response to resources published after a given ISO8601 compliant date.
beforestringLimit response to resources published before a given ISO8601 compliant date.
dates_are_gmtbooleanInterpret after and before as UTC dates when true.
excludestringEnsure result set excludes specific ids.
includestringLimit result set to specific ids.
offsetintegerOffset the result set by a specific number of items.
orderstringOrder sort attribute ascending or descending. Default is asc. Options: asc and desc.
orderbystringSort collection by object attribute. Default is date, Options: date, id, include, title and slug.
codestringLimit result set to resources with a specific code.

Update a coupon

This API lets you make changes to a coupon.

PUT /wp-json/wc/v1/coupons/<id>
curl -X PUT https://example.com/wp-json/wc/v1/coupons/113 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"amount": 5
}'

Delete a coupon

This API helps you delete a coupon.

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

Available parameters

ParameterTypeDescription
forcestringUse true whether to permanently delete the coupon, Default is false.

Batch update coupons

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

note

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

POST /wp-json/wc/v1/coupons/batch
curl -X POST https://example.com/wp-json/wc/v1/coupons/batch \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"create": [
{
"code": "20off",
"discount_type": "percent",
"amount": 20,
"individual_use": true,
"exclude_sale_items": true,
"minimum_amount": "100.00"
},
{
"code": "30off",
"discount_type": "percent",
"amount": 30,
"individual_use": true,
"exclude_sale_items": true,
"minimum_amount": "100.00"
}
],
"update": [
{
"id": 113,
"minimum_amount": "50.00"
}
],
"delete": [
137
]
}'