2026年11月14日
2026年11月14日
WooCommerce Coupons: Discount Types, Restrictions, Free Shipping, Code
This article is a localized edition of the Japanese original. Read the Japanese original
In WooCommerce, you create coupons from "Marketing" → "Coupons" in the admin screen. There are three discount types, and you can combine conditions such as minimum spend, expiry date, number of uses and eligible products.
The screen names and code in this article were checked in November 2026 on WooCommerce 11.2 (Japanese display) and WordPress 7.1.
Check that coupons are enabled
To use coupons, "Enable the use of coupon codes" must be checked under "Enable coupons" in "WooCommerce" → "Settings" → "General". It is checked by default on a fresh WooCommerce install.
If you check "Calculate coupon discounts sequentially" in the same place, then when several coupons are used, the first coupon is applied to the original price and the second to the price after the first discount.
When this setting is on, customers can enter coupon codes on the cart and checkout pages. There is no separate setting that only shows or hides the input field.
Create a coupon
- Open "Marketing" → "Coupons" and click "Add coupon".
- Enter the coupon code in the top field (for example
summer20). Clicking "Generate coupon code" fills in a random code. - If needed, write an internal note (such as the campaign name) in the "Description (optional)" field.
- Configure the three tabs in "Coupon data" below: "General", "Usage restriction" and "Usage limits" (described below).
- Click "Publish" to make the coupon usable.
Coupon codes are not case-sensitive. WooCommerce converts entered codes to lowercase, so entering SUMMER20 still uses the summer20 coupon.
“General” tab: discount type and amount
| Field | What it does |
|---|---|
| Discount type | Choose "Percentage discount", "Fixed cart discount" or "Fixed product discount" |
| Coupon amount | A percentage for a percentage discount (20 means 20%), an amount for the other two |
| Allow free shipping | When checked, the coupon grants free shipping (requires the setup below) |
| Coupon expiry date | The coupon expires at 00:00:00 on this date |
The discount types differ as follows.
- Percentage discount: discounts the eligible products by the given percentage.
- Fixed cart discount: takes the given amount off the whole cart once.
- Fixed product discount: takes the given amount off each eligible item. Buy two and you get the discount twice.
“Usage restriction” tab: when it can be used
| Field | What it does |
|---|---|
| Minimum spend / Maximum spend | The coupon works only when the subtotal is within this range |
| Individual use only | Prevents use together with other coupons |
| Exclude sale items | Does not apply to products on sale |
| Products / Exclude products | Products the coupon applies to, and products it does not |
| Product categories / Exclude categories | Categories the coupon applies to, and categories it does not |
| Allowed emails | The coupon works only on orders with the listed billing email addresses (comma-separated; * can be used, as in *@example.com) |
If you specify products or categories for a "Fixed cart discount", having those products in the cart becomes a condition for using the coupon.
“Usage limits” tab: how many times it can be used
| Field | What it does |
|---|---|
| Usage limit per coupon | How many times this coupon can be used in total |
| Limit usage to X items | For product discounts, the maximum number of items the discount applies to |
| Usage limit per user | How many times one person can use it (counted by user ID when logged in, by billing email for guests) |
Settings needed for free shipping coupons
Checking "Allow free shipping" on the coupon alone does not make shipping free. You also need to configure the shipping method.
- Open "WooCommerce" → "Settings" → "Shipping" and edit the shipping zone you want.
- Use "Add shipping method" to add "Free shipping".
- In the free shipping settings, set "Free shipping requires" to "A valid free shipping coupon" and save.
Orders that use a coupon with "Allow free shipping" checked can now choose the free shipping method.
Check and create coupons with WP-CLI
Coupons are stored as the shop_coupon post type. In WP-CLI, you can work with them through WooCommerce's wp wc shop_coupon commands (pass an administrator's username or ID to --user).
# List coupons (with usage count and expiry date)
wp wc shop_coupon list --user=admin --fields=id,code,amount,discount_type,usage_count,date_expires
# Create a coupon (500 JPY off the cart, subtotal of 3000 JPY or more)
wp wc shop_coupon create --user=admin --code=member10 --discount_type=fixed_cart --amount=500 --minimum_amount=3000
# Change the minimum spend
wp wc shop_coupon update 12 --user=admin --minimum_amount=5000
The values for --discount_type are percent for a percentage discount, fixed_cart for a fixed cart discount and fixed_product for a fixed product discount.
The settings are stored as custom fields, so you can also check them with wp post meta list.
wp post meta list 12 --format=table
The main keys are discount_type, coupon_amount, date_expires (Unix time), usage_count, usage_limit, usage_limit_per_user, minimum_amount, individual_use and free_shipping.
Create a coupon with PHP
When creating coupons in code, use the WC_Coupon class instead of writing each value with update_post_meta(). Save the following file as create-coupon.php and run it once with wp eval-file create-coupon.php. If you put it in functions.php, it runs on every page load, so avoid that.
<?php
/**
* Create one coupon (run once with wp eval-file)
*/
if ( ! class_exists( 'WC_Coupon' ) ) {
exit( "WooCommerce is not active\n" );
}
$code = 'summer20';
// Do not create it if a coupon with the same code exists
if ( wc_get_coupon_id_by_code( $code ) ) {
exit( "Already exists: {$code}\n" );
}
$coupon = new WC_Coupon();
$coupon->set_code( $code );
$coupon->set_discount_type( 'percent' ); // percent / fixed_cart / fixed_product
$coupon->set_amount( 20 ); // 20%
$coupon->set_minimum_amount( 3000 ); // Subtotal of 3,000 JPY or more
$coupon->set_individual_use( true ); // Individual use only
$coupon->set_usage_limit( 100 ); // Up to 100 uses in total
$coupon->set_usage_limit_per_user( 1 ); // Once per person
$coupon->set_date_expires( strtotime( '+30 days' ) );
$coupon->set_description( 'Summer campaign' );
$id = $coupon->save();
echo "Created: ID {$id}\n";
Apply coupons automatically
Apply a coupon automatically to logged-in members’ carts
The code below automatically applies the coupon member10 when a logged-in customer opens the cart or checkout page. If conditions such as the minimum spend are not met, it does nothing and shows no error notice. Save it as a PHP file in wp-content/mu-plugins/ or include it in your own plugin.
<?php
/**
* Plugin Name: Auto-apply a coupon to members' carts
*/
add_action( 'template_redirect', function () {
if ( ! function_exists( 'WC' ) || ! WC()->cart ) {
return;
}
if ( ! is_user_logged_in() || ! ( is_cart() || is_checkout() ) ) {
return;
}
$code = 'member10';
$cart = WC()->cart;
if ( $cart->is_empty() || $cart->has_discount( $code ) ) {
return;
}
// Do nothing if the conditions are not met (no error notice)
$coupon = new WC_Coupon( $code );
$valid = ( new WC_Discounts( $cart ) )->is_coupon_valid( $coupon );
if ( is_wp_error( $valid ) ) {
return;
}
$cart->apply_coupon( $code );
} );
template_redirect runs before the page is rendered, so this works with both the block cart and the shortcode cart. The woocommerce_before_cart action only runs on the shortcode cart, so it does not work with the block cart (the current WooCommerce default).
With this code, even if the customer removes the coupon, it is applied again the next time they open the cart. If you want customers to be able to remove it, add logic that records the removal in the session or similar.
Apply a coupon from a URL parameter
This code applies a coupon when someone opens a URL such as https://example.com/cart/?coupon=summer20. It is useful for newsletter and ad links.
<?php
/**
* Plugin Name: Apply a coupon from a URL parameter
*/
add_action( 'template_redirect', function () {
if ( empty( $_GET['coupon'] ) || ! function_exists( 'WC' ) || ! WC()->cart ) {
return;
}
$code = wc_format_coupon_code( sanitize_text_field( wp_unslash( $_GET['coupon'] ) ) );
if ( '' === $code || WC()->cart->has_discount( $code ) ) {
return;
}
// An error notice is shown if conditions (such as minimum spend) are not met
WC()->cart->apply_coupon( $code );
} );
In our test, opening this URL with an empty cart did not keep the coupon. Add the parameter to URLs that are opened after products are in the cart (the cart or checkout page).
Check coupon usage
- In the coupon list ("Marketing" → "Coupons"), the "Usage / Limit" column shows how many times each coupon has been used and its limit.
- "Analytics" → "Coupons" shows the number of uses and the discount amount for each period.
- In WP-CLI, check the
usage_countin thewp wc shop_coupon listoutput shown earlier.
Related articles
Questions about WordPress? The publisher of this site is based in Japan and replies in Japanese. Contact (Japanese)