Adding a coupon to WooCommerce is a great way to offer discounts and incentives to customers. There are two ways to add coupons:
1. Through the WordPress Admin
To add a coupon through the WordPress admin, go to “WooCommerce” > “Coupons”. From here, you can either “add a new coupon” or “import coupons”. If you want to add a new coupon, click on the “Add Coupon” button. This will bring up a form where you can enter your coupon details.
Coupon Data
The first thing you need to do is enter a “coupon code”.
This is the code that customers will use to apply the coupon. Next, you need to choose a description. This is for internal use only and will help you remember what the coupon is for. Finally, you need to choose an expiry date. This is the date on which the coupon will expire and can no longer be used.
Discount Type
The next thing you need to do is choose a discount type. There are three options:
- Percentage Discount: This will give the customer a percentage off their purchase price.
- Fixed Cart Discount: This will give the customer a fixed discount off their purchase price.
- “Free Shipping” Discount: This will give the customer free shipping on their purchase.
“Usage Restrictions” tab
The next thing you need to do is choose how many times this coupon can be used. You can choose from four options:
– Unlimited usage
– Per user (the customer can only use it once)
– Per item (the customer can only use it once per item)
– Custom usage limit (you can set a custom limit)
The final thing you need to do is click on the “Add Coupon” button. This will save your changes and add the coupon to your WooCommerce store.
2. Adding a Coupon Through Code
If you want more control over your coupons, or if you want to automate the process of adding coupons, you can do so through code. To do this, you’ll need to add some code to your functions.php file.
The first thing you need to do is define your function.
function my_custom_coupon() {
// Your code goes here }
Next, you need to add an action hook.
add_action( 'init', 'my_custom_coupon' );
Now that your function is defined and hooked into WordPress, you can start adding your code. The first thing you need to do is create a new instance of the WC_Coupon class.
$coupon = new WC_Coupon();
Now that you have an instance of the WC_Coupon class, you can start setting properties. The first property you need to set is the code.
You can set the code by using the following function:
$coupon->set_code( $code ); // Code goes here.
The next property you need to set is the description.
You can set the description by using the following function:
$coupon->set_description( $description ); // Description goes here.
The next property you need to set is the expiry date.
You can set the expiry date by using one of two functions:
$coupon->set_expiry_date( $expiry_date ); // Expiry date goes here.
OR
$coupon->set_expiry_date( 'yyyy-mm-dd hh:mm:ss' ); // Expiry date goes here in GMT timezone.
The next property you need to set is the discount type. You can set the discount type by using one of three functions :
$coupon->set_discount_type($discount_type); // Discount type goes here. Can be 'fixed_cart', 'percent', or 'fixed_product'.
OR
$coupon->set_discount_type($type, $amount); // Type goes here. Amount goes here as an integer or float.
OR
$coupon->set_discount_type(); // No discount type.
OR
$coupon->set_discount_amount($amount); // Discount amount. Float or int.
OR
$coupon->set_discount_taxable(true|false); // Whether or not discount amount is taxable. Default is true.
The next property you need to set is the amount this coupon can be used. You can set this by using the following function :
$coupon->set_usage_limit(int); // Sets how many times this can be used before it expires
OR
$coupon->set_usage_limit_per_user(int); // Sets how many times this can be used per user before it expires
OR
$coupon->set_usage_restrictions(array('minimum', 'maximum', ) ); // Sets restrictions on usage limits per order, per item, etc
Once you have set all of your properties, you need to save the coupon to the database by using the following function:
$coupon->save(); // Saves changes made to meta data to database
And that’s it! You have now successfully added a coupon to your WooCommerce store!
1. Make sure you understand the coupon settings. There are options for how the coupon can be used, how many times it can be used, when it expires, etc. Make sure you understand these settings before creating the coupon.
2. If you are using a code generator to create your coupons, please be aware that there is a potential for errors. Make sure you check the generated code carefully before using it.
3. Be aware of the expiration date of the coupon. If the coupon expires before it is used, it will not work.
4. Make sure the coupon is applied to the correct products/services. If the coupon is not applied correctly, it will not work.