Conditional Discount
Overview
The Conditional Discount function follows an “if X is true, apply discount Y” pattern. It is the simplest and most common discount type in Alfo, and it covers most of the promotions merchants run.
| Property | Value |
|---|---|
| Discount Classes | Product, Order, Shipping |
| Billing | Starter plan and above |
| Condition Support | Full set: all 16 conditions (9 cart-level + 7 product-level) |
The Conditional Discount supports all three discount classes and the complete condition library, so it fits most promotions. Choose it when your discount logic does not need escalating tiers, buy/get mechanics, or bundle validation.
Real-Life Use Cases
1. 10% Off Orders Over $100
An order-level promotion. When the cart subtotal exceeds $100, every customer receives a flat 10% order discount.
| Setting | Value |
|---|---|
| Condition | cartSubtotal greater than or equal to 100 |
| Target | Order |
| Discount | Percentage, 10% |
2. Free Shipping for VIP Customers
Loyalty program members get free shipping on every order. Customers tagged “VIP” in Shopify qualify automatically.
| Setting | Value |
|---|---|
| Condition | customerTag hasAny ["VIP"] |
| Target | Shipping, scope “all” |
| Discount | Percentage, 100% |
3. 15% Off All “Sale” Tagged Items
A site-wide sale that applies only to the products you have tagged. Non-sale items in the same cart stay at full price.
| Setting | Value |
|---|---|
| Condition | productTag hasAny ["Sale"] |
| Target | Product, scope “filtered” (only tagged items receive the discount) |
| Discount | Percentage, 15% |
4. $5 Off for First-Time Customers
A small incentive for new shoppers. Shopify exposes the customer’s historical order count, so you can target shoppers who have never placed an order.
| Setting | Value |
|---|---|
| Condition | customerOrderCount equals 0 |
| Target | Order |
| Discount | Fixed amount, $5 |
5. 20% Off a Specific Collection When Cart Has 3+ Items
This example combines cart-level and product-level conditions with AND logic. The customer must have at least 3 items in the cart, and the discount applies only to products in the designated collection.
| Setting | Value |
|---|---|
| Conditions (AND) | cartTotalQuantity greater than or equal to 3; collection hasAny ["Summer Essentials"] |
| Target | Product, scope “filtered” |
| Discount | Percentage, 20% |
How It Works
Execution Flow for Cart Lines (Product and Order Discounts)
- Read the configuration. The function loads the JSON metafield containing version, strategy, rule groups, and rejection rules.
- Evaluate the rejection rules. If any rejection rule matches, the function exits early with no discount.
- Check the discount classes. The function determines whether the current run targets product discounts, order discounts, or both.
- For each rule group:
- Evaluate the group’s conditions against the cart and customer context.
- Filter eligible cart lines based on product-level conditions (tags, collections, etc.).
- Build discount candidates for each qualifying line or the order total.
- Check the strategy. The configured strategy (
first,best, orall) decides which rule group’s discounts are returned.
Execution Flow for Delivery Options (Shipping Discounts)
- Check the shipping class. Confirm the discount is configured to apply to shipping.
- For each rule group:
- Evaluate cart-level conditions. Product-level conditions do not apply to shipping.
- Resolve the shipping scope (
alldelivery options or specific ones). - Build the delivery discount output.
Step-by-Step Setup
The following walkthrough creates a “Summer Sale 20% Off Tagged Products” discount.
Step 1: Create the Discount
Navigate to Shopify Admin > Discounts > Create discount. Choose either Automatic discount or Discount code. In the app selection, pick Conditional Discount Function.
Step 2: Add Conditions
In the rule builder, add a product-level condition:
| Setting | Value |
|---|---|
| Type | productTag |
| Operator | hasAny |
| Value | ["summer-sale"] |
Only products carrying the “summer-sale” tag are then eligible.
Step 3: Set the Target
Set the class to Product and the scope to Filtered, so only the items matching the condition receive the discount.
Step 4: Set the Discount Value
| Setting | Value |
|---|---|
| Type | Percentage |
| Value | 20 |
| Message | ”Summer Sale 20% OFF” |
The message appears in the cart and checkout UI so customers understand why the price changed.
Step 5: Save
Click Save to activate the discount. It takes effect immediately for automatic discounts, or when the code is entered for code-based discounts.
Configuration Example
The following JSON is the complete configuration for the Summer Sale discount described above.
{
"version": "1.0",
"strategy": "first",
"productTags": ["summer-sale"],
"ruleGroups": [
{
"id": "rg_001",
"name": "Summer Sale",
"enabled": true,
"conditionLogic": "and",
"conditions": [
{
"type": "productTag",
"operator": "hasAny",
"tags": ["summer-sale"]
}
],
"targets": {
"product": { "scope": "filtered" }
},
"discount": {
"type": "percentage",
"value": 20,
"message": "Summer Sale 20% OFF"
}
}
],
"rejectionRules": []
}
Key Fields
| Field | Purpose |
|---|---|
version | Configuration schema version. Always "1.0" for current releases. |
strategy | How to handle multiple matching rule groups: "first" (stop at the first match), "best" (pick the largest discount), or "all" (apply all matches). |
productTags | Top-level declaration of tags the function needs to query. Required for Shopify’s input query. |
ruleGroups | Array of rule group objects, each containing conditions, targets, and discount definitions. |
conditionLogic | "and" requires all conditions to pass. "or" requires at least one. |
rejectionRules | Array of conditions that, if matched, prevent any discount from being applied. |
Multi-Rule Example: VIP + General Discount
This configuration holds two rule groups in a single discount function. The strategy is "first", so the function evaluates rule groups in order and stops at the first match. VIP customers receive 30% off. Everyone else gets 10% off orders over $50.
{
"version": "1.0",
"strategy": "first",
"ruleGroups": [
{
"id": "rg_001",
"name": "VIP 30% Off",
"enabled": true,
"conditionLogic": "and",
"conditions": [
{
"type": "customerTag",
"operator": "hasAny",
"tags": ["VIP"]
}
],
"targets": {
"order": {}
},
"discount": {
"type": "percentage",
"value": 30,
"message": "VIP Exclusive 30% OFF"
}
},
{
"id": "rg_002",
"name": "General 10% Off $50+",
"enabled": true,
"conditionLogic": "and",
"conditions": [
{
"type": "cartSubtotal",
"operator": "greaterThanOrEqualTo",
"value": 50
}
],
"targets": {
"order": {}
},
"discount": {
"type": "percentage",
"value": 10,
"message": "10% OFF orders over $50"
}
}
],
"rejectionRules": []
}
Because the strategy is "first", a VIP customer with a $60 cart receives 30% off. Rule group 1 matches and evaluation stops. A non-VIP customer with a $60 cart skips rule group 1 and receives 10% off from rule group 2. A non-VIP customer with a $30 cart receives no discount.
Shipping Discount Example
Free shipping for orders over $75.
{
"version": "1.0",
"strategy": "first",
"ruleGroups": [
{
"id": "rg_001",
"name": "Free Shipping Over $75",
"enabled": true,
"conditionLogic": "and",
"conditions": [
{
"type": "cartSubtotal",
"operator": "greaterThanOrEqualTo",
"value": 75
}
],
"targets": {
"shipping": { "scope": "all" }
},
"discount": {
"type": "percentage",
"value": 100,
"message": "Free Shipping on $75+"
}
}
],
"rejectionRules": []
}
This applies a 100% shipping discount to all delivery options when the cart subtotal is $75 or more. The scope "all" ensures every shipping method is discounted, not just the cheapest one.
Next Steps
- Tiered Discount: escalating discounts based on quantity or spending thresholds.
- Buy X Get Y: buy-one-get-one and promotional bundle offers.
- Bundle Discount: discounts that require specific product combinations.