Discount Functions

Custom discount logic and checkout rules for Shopify

Last updated: 2025-01-16

Discount Functions extend Shopify's native discount capabilities with custom logic. Create complex discount rules that aren't possible with standard Shopify discounts — tiered pricing, conditional discounts, BOGO variations, and more.

Shopify Functions

Discount Functions are built on Shopify Functions, running directly in Shopify's infrastructure for maximum performance and reliability.

What Discount Functions Can Do

Discount Capabilities

  • Tiered discounts — Spend more, save more
  • BOGO variations — Buy X get Y at Z% off
  • Volume pricing — Price breaks at quantity thresholds
  • Customer-specific discounts — VIP, wholesale, first-time
  • Product combination discounts — Bundle pricing logic
  • Time-based discounts — Happy hour, flash sales
  • Conditional discounts — Based on cart contents, customer tags
  • Stacking rules — Control how discounts combine

How It Works

  1. Define discount rules — Set up conditions and discount logic
  2. Cart evaluation — CheckoutOS evaluates rules at checkout
  3. Discount calculation — Applicable discounts computed
  4. Shopify application — Discounts applied via Shopify Functions
  5. Customer sees savings — Discounts reflected in checkout

Discount Types

Automatic Discounts

Applied automatically when conditions are met:

Automatic Discount
{
  "discount": {
    "name": "Summer Sale 20%",
    "type": "automatic",
    "trigger": "cart_qualifies",
    "conditions": {
      "min_cart_value": 50,
      "collections": ["summer-collection"]
    },
    "discount_value": {
      "type": "percentage",
      "value": 20
    }
  }
}

Code-Based Discounts

Require customer to enter a code:

Code Discount
{
  "discount": {
    "name": "VIP20",
    "type": "code",
    "code": "VIP20",
    "conditions": {
      "customer_tag": "vip",
      "usage_limit": 1000,
      "per_customer_limit": 1
    },
    "discount_value": {
      "type": "percentage",
      "value": 20
    }
  }
}

Tiered Discounts

Increasing discounts based on spend or quantity:

Tiered Discount
{
  "discount": {
    "name": "Spend More Save More",
    "type": "tiered",
    "tiers": [
      { "threshold": 50, "discount": 10, "message": "Save 10%" },
      { "threshold": 100, "discount": 15, "message": "Save 15%" },
      { "threshold": 200, "discount": 20, "message": "Save 20%" }
    ],
    "show_next_tier": true
  }
}

BOGO Discounts

Buy X get Y free or discounted:

BOGO Discount
{
  "discount": {
    "name": "Buy 2 Get 1 Free",
    "type": "bogo",
    "buy": {
      "quantity": 2,
      "products": "any_in_collection",
      "collection": "t-shirts"
    },
    "get": {
      "quantity": 1,
      "discount": 100,
      "applies_to": "cheapest"
    }
  }
}

Discount Conditions

Available Conditions

  • Cart value — Minimum or maximum spend
  • Product quantity — Number of items in cart
  • Specific products — Include or exclude products
  • Collections — Products from specific collections
  • Customer tags — VIP, wholesale, first-time
  • Customer email domain — B2B email matching
  • Order count — First order, returning customer
  • Date/time — Specific periods or recurring times
  • Shipping destination — Country, region, postal code

Discount Stacking

Control how multiple discounts interact:

Stacking Rules
{
  "stacking": {
    "allow_code_with_automatic": true,
    "allow_multiple_automatic": false,
    "priority_order": ["vip_discount", "tiered_discount", "sale_discount"],
    "max_discounts": 2,
    "max_discount_percentage": 50
  }
}

Discount Display

Configure how discounts appear to customers:

Display Options
{
  "display": {
    "show_savings": true,
    "savings_format": "You save ${{amount}}",
    "show_discount_name": true,
    "show_next_tier": true,
    "next_tier_message": "Spend ${{remaining}} more to save {{next_discount}}%",
    "strikethrough_original": true
  }
}

Discount Analytics

Track discount performance:

  • Usage count and revenue impact
  • Average discount per order
  • Conversion lift from discounts
  • Margin impact analysis

Explore Discount Types

Was this page helpful?

Need more help? Contact support