How to Create a Discount Code
The Discount Codes addon lets you offer savings to your clients through coupon codes they enter at checkout — or through automatic discounts that apply on their own when conditions are met.
Requirements
The Discount Codes addon must be installed and activated.
Creating a Discount Code
- Go to Sunshine > Discounts in your WordPress dashboard
- Click Add New
- Give the discount a name (this is for your reference only — customers won't see it)
- Fill in the settings described below
- Click Publish
General Settings
Automatic Discount
Check the Automatic box if you want this discount to apply automatically when its conditions are met. When enabled, customers don't need to enter a code — the discount is applied for them at checkout and they cannot remove it.
When automatic is unchecked, a Code field appears. This is the coupon code your customers will type in at checkout. You can type your own code or click the Generate Code button to create a random one.
Discount Type
Choose how the discount is calculated:
- Percent off total order — A percentage off the entire order subtotal
- Amount off total order — A fixed dollar amount off the entire order
- Percent off per product — A percentage off each qualifying product in the cart
- Amount off per product — A fixed dollar amount off each qualifying product in the cart
Discount Amount
Enter the value of the discount. For percentage types, enter a number like 10 for 10% off. For fixed amount types, enter a dollar value like 5.00.
Apply to Shipping
When using a percentage-based discount, check this box to also apply the percentage discount to the shipping cost.
Free Shipping
Check this box to give customers free shipping when this discount is applied. This requires a shipping method that supports discount-based free shipping to be active.
Restrictions
Restrictions let you control when and how the discount can be used.
Date Restrictions
- Start Date — The discount won't be valid before this date
- End Date — The discount expires after this date
Leave either field blank if you don't need that restriction.
Solo Discount
Check the Solo box to make this an exclusive discount. When applied, all other discounts are removed and no additional discounts can be combined with it.
Product Restrictions
- Required Products — The customer must have these specific products in their cart before the discount applies. This is useful for "buy X, get Y" style promotions.
- Allowed Products — The discount only applies to these products. Other products in the cart are unaffected.
- Disallowed Products — The discount does not apply to these products, even if they otherwise qualify.
Category Restrictions
- Allowed Categories — The discount only applies to products in these categories
- Disallowed Categories — Products in these categories are excluded from the discount
Gallery Restrictions
- Allowed Galleries — The discount only applies to items from these galleries (child galleries are included automatically)
- Disallowed Galleries — Items from these galleries are excluded from the discount
Limits
Minimum Order Amount
Set a minimum cart subtotal required before the discount can be used. For example, enter 50.00 to require at least $50 in the cart.
Minimum Quantity
Set a minimum number of items that must be in the cart before the discount applies.
Max Uses
The maximum number of times this discount code can be used across all customers. Once reached, the code stops working.
Max Uses Per Person
The maximum number of times a single logged-in customer can use this discount code.
Max Product Quantity
For product-level discounts only. Limits how many units of a single product the discount applies to. For example, if set to 2 and a customer orders 5 prints, only 2 of them receive the discounted price.
How Customers Use Discount Codes
At checkout, customers see a field labeled "Discount Code or Gift Card" where they can type in a code and click Apply. The discount appears in their order summary and the total updates automatically.
Customers can remove a discount they entered by clicking the × button next to it. Automatic discounts cannot be removed.
Applying a Discount via URL
You can also apply a discount automatically by sharing a URL with the discount code as a parameter:
https://yoursite.com/?discount=YOURCODE
When a customer visits this link, the discount is applied to their cart and they see a confirmation message.
Tracking Usage
On the Sunshine > Discounts screen, the Usage column shows how many times each discount has been used out of its maximum. This helps you monitor which codes are being redeemed and when they're approaching their limits.
Hooks and Filters
sunshine_discount_amount
Modify the discount amount programmatically.
add_filter( 'sunshine_discount_amount', function( $amount, $discount ) {
// Double the discount for a specific code
if ( $discount->get_code() === 'VIP' ) {
$amount = $amount * 2;
}
return $amount;
}, 10, 2 );
Learn how to add this custom code to your WordPress website
sunshine_cart_discount
Modify the final calculated discount total before it's applied to the cart.
add_filter( 'sunshine_cart_discount', function( $discount_total ) {
// Cap the maximum discount at $50
if ( $discount_total > 50 ) {
$discount_total = 50;
}
return $discount_total;
});
Learn how to add this custom code to your WordPress website
sunshine_after_discount_form
Add custom content after the discount code form at checkout.
add_action( 'sunshine_after_discount_form', function() {
echo '<p class="discount-hint">Have a coupon code? Enter it above.</p>';
});
Learn how to add this custom code to your WordPress website
Still need help?
If you have not yet found your answer in the documentation articles, please contact support