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.

PropertyValue
Discount ClassesProduct, Order, Shipping
BillingStarter plan and above
Condition SupportFull 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.

SettingValue
ConditioncartSubtotal greater than or equal to 100
TargetOrder
DiscountPercentage, 10%

2. Free Shipping for VIP Customers

Loyalty program members get free shipping on every order. Customers tagged “VIP” in Shopify qualify automatically.

SettingValue
ConditioncustomerTag hasAny ["VIP"]
TargetShipping, scope “all”
DiscountPercentage, 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.

SettingValue
ConditionproductTag hasAny ["Sale"]
TargetProduct, scope “filtered” (only tagged items receive the discount)
DiscountPercentage, 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.

SettingValue
ConditioncustomerOrderCount equals 0
TargetOrder
DiscountFixed 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.

SettingValue
Conditions (AND)cartTotalQuantity greater than or equal to 3; collection hasAny ["Summer Essentials"]
TargetProduct, scope “filtered”
DiscountPercentage, 20%

How It Works

Execution Flow for Cart Lines (Product and Order Discounts)

  1. Read the configuration. The function loads the JSON metafield containing version, strategy, rule groups, and rejection rules.
  2. Evaluate the rejection rules. If any rejection rule matches, the function exits early with no discount.
  3. Check the discount classes. The function determines whether the current run targets product discounts, order discounts, or both.
  4. 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.
  5. Check the strategy. The configured strategy (first, best, or all) decides which rule group’s discounts are returned.

Execution Flow for Delivery Options (Shipping Discounts)

  1. Check the shipping class. Confirm the discount is configured to apply to shipping.
  2. For each rule group:
    • Evaluate cart-level conditions. Product-level conditions do not apply to shipping.
    • Resolve the shipping scope (all delivery 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:

SettingValue
TypeproductTag
OperatorhasAny
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

SettingValue
TypePercentage
Value20
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

FieldPurpose
versionConfiguration schema version. Always "1.0" for current releases.
strategyHow to handle multiple matching rule groups: "first" (stop at the first match), "best" (pick the largest discount), or "all" (apply all matches).
productTagsTop-level declaration of tags the function needs to query. Required for Shopify’s input query.
ruleGroupsArray of rule group objects, each containing conditions, targets, and discount definitions.
conditionLogic"and" requires all conditions to pass. "or" requires at least one.
rejectionRulesArray 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.