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
- Products/variants must have discount data stored in metafields
- The function must be configured to read metafield inputs
- Metafields must contain numeric values
- Use metafield input references instead of fixed values
How It Works
- In the discount configuration, select a metafield input reference instead of entering a fixed value
- When the function runs, it reads the metafield value for each product/variant
- Each item receives its own discount based on its metafield value
- Items without the metafield are skipped (no discount applied)
Examples
Product-specific percentage discounts:
| Product | Metafield Value | Result |
|---|---|---|
| Product A | 20 | Gets 20% off |
| Product B | 15 | Gets 15% off |
| Product C | (no metafield) | No discount |
Individual clearance amounts:
| Product | Metafield Value | Result |
|---|---|---|
| Shirt | 10 | Gets $10 off |
| Pants | 25 | Gets $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
- Products must have custom price data stored in metafields
- The function must be configured to read metafield inputs
- Metafields must contain numeric values (prices)
How It Works
- Select the metafield containing your custom base prices
- Percentage discounts calculate from the metafield price instead of the regular price
- Can be combined with metafield-based discount values for full customization
Example
| Setting | Value |
|---|---|
| Regular price | $100 |
| Base price metafield | $80 (wholesale price) |
| Discount percentage | 25% |
Calculation comparison:
| Calculation Type | Formula | Discount |
|---|---|---|
| Normal | 25% of $100 | $25 off |
| With custom base | 25% 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
- Use a metafield input reference instead of a fixed price value
- Each product gets its own target price from its metafield
- The system calculates the appropriate discount to reach that target price
- Items without the metafield are skipped
Example
| Product | Regular Price | Metafield Value | Result |
|---|---|---|---|
| Product A | $50 | 35 | Discounted to $35 |
| Product B | $80 | 60 | Discounted 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:
- Go to Settings → Custom data
- Add metafield definitions to Products or Variants
- Use a numeric type (Number, Decimal, or Money)
- Set values on individual products
Step 2: Configure Function Inputs
In Function Studio:
- Add a metafield input to your function
- Specify the metafield namespace and key
- Choose whether to read from product or variant metafields
Step 3: Reference in Discount Settings
When configuring your discount:
- Instead of entering a fixed value, select “Use metafield input”
- Choose the metafield input you configured
- 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:
- Check if product has the metafield
- Read the metafield value
- Apply discount based on that value
- 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_discountmetafield 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_pricemetafield for base prices - Create
member_discountmetafield 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_pricemetafield - 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
Related Documentation
- Basic Discount Settings - Discount types and strategies
- Quantity Logic - Quantity-based settings
- Cart Line Groups - Targeting specific products