Metafield Discounts

Use product and variant metafields to create dynamic, per-product discount values, custom base pricing, and individual fixed prices.

Metafield Discounts

Metafield-based discounts let you apply different discount values to individual products based on data stored in Shopify metafields. Instead of a single fixed discount for all products, each item can have its own discount percentage, amount, or target price.

Overview

With metafield discounts, you can:

  • Set individual discount percentages per product
  • Apply product-specific fixed amounts
  • Define custom target prices for each item
  • Calculate discounts from custom base prices (like wholesale pricing)

Metafield-Based Discount Values

What It Does

Instead of entering a fixed discount value (like “20%”), you reference a metafield that contains the discount value for each product. Each product gets its own discount based on its metafield value.

Available For

All discount types:

  • Percentage discounts
  • Fixed amount discounts
  • Fixed price discounts

Use Cases

  • Product-specific discount percentages: Different clearance percentages per item
  • Individual clearance pricing: Each product has its own markdown amount
  • Tiered member discounts: VIP discounts vary by product category
  • Dynamic promotional pricing: Sale percentages set per product in Shopify admin

Setup Requirements

  1. Products/variants must have discount data stored in metafields
  2. The function must be configured to read metafield inputs
  3. Metafields must contain numeric values
  4. Use metafield input references instead of fixed values

How It Works

  1. In the discount configuration, select a metafield input reference instead of entering a fixed value
  2. When the function runs, it reads the metafield value for each product/variant
  3. Each item receives its own discount based on its metafield value
  4. Items without the metafield are skipped (no discount applied)

Examples

Product-specific percentage discounts:

ProductMetafield ValueResult
Product A20Gets 20% off
Product B15Gets 15% off
Product C(no metafield)No discount

Individual clearance amounts:

ProductMetafield ValueResult
Shirt10Gets $10 off
Pants25Gets $25 off
Shoes(no metafield)No discount

Custom Base Pricing

What It Does

Calculate percentage discounts from a custom price stored in a metafield, instead of the regular product price.

Available For

Percentage discounts only.

Use Cases

  • Wholesale pricing tiers: Calculate discounts from wholesale cost
  • Member-only pricing: Use member base prices for VIP discounts
  • Seasonal price adjustments: Discount from adjusted seasonal prices
  • Compare-at pricing: Calculate savings from original prices

Setup Requirements

  1. Products must have custom price data stored in metafields
  2. The function must be configured to read metafield inputs
  3. Metafields must contain numeric values (prices)

How It Works

  1. Select the metafield containing your custom base prices
  2. Percentage discounts calculate from the metafield price instead of the regular price
  3. Can be combined with metafield-based discount values for full customization

Example

SettingValue
Regular price$100
Base price metafield$80 (wholesale price)
Discount percentage25%

Calculation comparison:

Calculation TypeFormulaDiscount
Normal25% of $100$25 off
With custom base25% of $80$20 off

Combining with Metafield Discount Values

You can use both features together:

  • Base price from metafield A
  • Discount percentage from metafield B

This allows complete per-product pricing control.


Metafield Support for Fixed Price Discounts

What It Does

Set individual target prices per product from metafields, rather than a single fixed bundle price.

How It Works

  1. Use a metafield input reference instead of a fixed price value
  2. Each product gets its own target price from its metafield
  3. The system calculates the appropriate discount to reach that target price
  4. Items without the metafield are skipped

Example

ProductRegular PriceMetafield ValueResult
Product A$5035Discounted to $35
Product B$8060Discounted to $60
Product C$30(no metafield)No discount

Use Cases

  • Per-product sale prices managed in Shopify admin
  • Flash sale pricing set via metafields
  • Clearance pricing that varies by product

Setting Up Metafield Inputs

Step 1: Create Metafields in Shopify

In your Shopify admin:

  1. Go to Settings → Custom data
  2. Add metafield definitions to Products or Variants
  3. Use a numeric type (Number, Decimal, or Money)
  4. Set values on individual products

Step 2: Configure Function Inputs

In Function Studio:

  1. Add a metafield input to your function
  2. Specify the metafield namespace and key
  3. Choose whether to read from product or variant metafields

Step 3: Reference in Discount Settings

When configuring your discount:

  1. Instead of entering a fixed value, select “Use metafield input”
  2. Choose the metafield input you configured
  3. The discount will use the metafield value for each product

Dynamic Message Placeholders

Metafield-based discounts work with message placeholders:

{{percentage}} Placeholder

Shows the calculated percentage for each item. Since each item may have a different discount, the message dynamically reflects the actual discount applied.

Example: “Save {{percentage}} on this item” shows the correct percentage for each discounted product.

{{amount}} Placeholder

Shows the monetary discount amount with proper currency formatting. Useful for:

  • Metafield-based fixed amounts
  • Metafield-based fixed prices
  • Any dynamic monetary discount

Example: “Special price: {{amount}}” displays the actual discounted price.


Important Notes

Items Without Metafields

Products that don’t have the specified metafield will not receive any discount. This is intentional - it lets you selectively apply discounts only to products with configured values.

Metafield Value Requirements

  • Values must be positive numbers
  • For percentages: use whole numbers (20 for 20%, not 0.20)
  • For amounts/prices: use the numeric value in your store’s currency

Processing Order

Each item is processed individually:

  1. Check if product has the metafield
  2. Read the metafield value
  3. Apply discount based on that value
  4. Move to next item

Combining Features

You can combine metafield features:

  • Metafield discount value + fixed base price
  • Fixed discount value + metafield base price
  • Metafield discount value + metafield base price

Common Patterns

Clearance Pricing by Product

Setup:

  • Create clearance_discount metafield on products
  • Set percentage values (10, 20, 30, etc.) on clearance items
  • Reference metafield in percentage discount

Result: Each clearance item gets its designated markdown.

Member Wholesale Pricing

Setup:

  • Create wholesale_price metafield for base prices
  • Create member_discount metafield for discount percentages
  • Use both in discount configuration

Result: Members get discounts calculated from wholesale prices, varying by product.

Flash Sale with Individual Prices

Setup:

  • Create flash_sale_price metafield
  • Set target prices on sale items
  • Use in fixed price discount

Result: Each product sells at its designated flash sale price.


Troubleshooting

Discount Not Applying

  • Verify the product has the metafield defined
  • Check that the metafield contains a numeric value
  • Confirm the metafield input is correctly configured in the function

Wrong Discount Amount

  • Check the metafield value on the specific product
  • Verify you’re using the correct metafield (product vs variant level)
  • Ensure the value is in the expected format (whole number for percentage)

Some Products Skipped

This is expected behavior - products without the metafield don’t receive discounts. Either:

  • Add the metafield to those products, or
  • Use a fixed discount value for products without metafields