Coupon Data
Anitaa Murthy edited this page Jan 6, 2022
·
3 revisions
In an effort to unify CLI, API, and WP Admin, new CRUD classes are being implemented to form a new 'data manipulation API'.
Each CRUD class contains a representation of the data in array format which can be used by endpoints. This representation may differ from the actual stored 'meta keys' mainly due to legacy, but should represent the objects more clearly.
This document explains the Coupon CRUD.
Name | Type | Description | Example |
---|---|---|---|
id |
int |
Coupon ID | 1 |
date_created |
`WC_DateTime | null` |
WC_DateTime object for when coupon was created or null if not set. Read only. |
date_modified |
`WC_DateTime | null` |
WC_DateTime object for when coupon was last modified or null if not set. Read only. |
code |
string |
Coupon code | test-coupon |
description |
string |
Explanation of what the coupon does. | Take 50% off your next order of $10 or more + free shipping! |
discount_type |
string |
Type of discount. Valid values: fixed_cart , percent , fixed_product , percent_product . |
percent |
amount |
float |
Amount off provided by the coupon. Ran through wc_format_decimal . |
50 |
status |
string |
Status of the coupon. Valid values: publish , draft , pending , trash , auto-draft . |
publish |
date_expires |
`WC_DateTime | null` |
WC_DateTime object for when the coupon expires or null if not set. |
usage_count |
int |
How many times the coupon has been used. | 15 |
individual_use |
bool |
Individual use means this coupon cannot be used in conjunction with other coupons. | true |
product_ids |
array |
Product IDs this coupon can be used with. | array( 322, 345 ) |
excluded_product_ids |
array |
Product IDs this coupon cannot be used with. | array( 295 ) |
usage_limit |
int |
Amount of times this coupon can be used globally. | 200 |
usage_limit_per_user |
int |
Amount of times this coupon can be used by a customer. | 1 |
limit_usage_to_x_items |
int |
The number of products in your cart this coupon can apply to (for product discounts). | 0 |
free_shipping |
bool |
Does this coupon grant free shipping? | true |
product_categories |
array |
Product categories this coupon can be used with. | array( 22 ) |
excluded_product_categories |
array |
Product categories this coupon cannot be used with. | array( 26 ) |
exclude_sale_items |
bool |
Excluding sale items mean this coupon cannot be used on items that are on sale (or carts that contain on sale items). | false |
minimum_amount |
float |
Minimum spend amount that must be met before this coupon can be used. Ran through wc_format_decimal . |
10.00 |
maximum_amount |
float |
Maximum spend amount that must be met before this coupon can be used Ran through wc_format_decimal . |
500.00 |
email_restrictions |
array |
Only customers with a matching email address can use the coupon. | array( 'test@test.local', 'woo@test.local' ) |
used_by |
array |
List of user IDs who have used the coupon. | array( 63 ) |
custom_fields |
array |
Read only array of all custom fields associated with this coupon. | array( '_wc_points_modifier' => 2 ) |
custom_field |
string |
Single custom field associated with this coupon. | 2 |
discount_amount |
float |
Read only discount total for an item or cart. | 10.00 |
WooCommerce is an open source commerce platform built for WordPress and lovingly crafted by Automattic and the WooCommerce community 💜. Come and work with us!
Contribution
- Set up development environment
- Our Git Flow
- SCSS and JS minification
- Naming conventions
- CSS SASS coding guidelines and naming conventions
- Critical Flows
- API Critical Flows
- String localisation guidelines
- Translating WooCommerce
- Deprecation in core
- Adding Actions and Filters
- Common Issues
- Writing high-quality testing instructions
Release Notes
- Release Testing Instructions
- 3.6.x notes/FAQ
- 2.6.x to 3.0.0 Developer Migration Notes
- Select2 fields not working in 3.0.x
- Thumbnail Image Regeneration in 3.3+
- Customizing image sizes in 3.3+
REST API and CLI
CRUD & Data Descriptions
- Database Description
- CRUD Objects in 3.0
- Order and Order Line Item Data
- Coupon Data
- Customer Data
- Product Data
- Data Stores
Internal APIs
Theming
- Enabling product gallery features (zoom, swipe, lightbox)
- Template File Guidelines for Devs and Theme Authors
Examples / Guides