Discount function · Plan: Basic
Can a discount read its percentage or eligibility from a product metafield or a metaobject?
Yes. A rule's value can come from a product or variant metafield, and conditions can test metafield values. On the Advanced plan rules can also read synced metaobject entries, so a table of offers lives in Shopify admin and one function applies all of it.
- Function typeDiscount
- Plan neededBasic
- Shopify PlusNot required
- Updated
Why do this
Merchandising teams change offers more often than developers change rules. With the percentage in a metafield, “20% off this product this week” is an edit in the product admin, in bulk, or through an import, and the function keeps working untouched.
How the rule is built
Value from a metafield (Basic).
- In the function’s data access, select the product or variant metafield to read, for example
custom.discount_percent. - Add a product discount rule with the condition
product metafield exists(or> 0). - Set the value to a percentage whose source is that metafield.
Every product with the metafield set gets its own percentage; products without it are untouched.
Conditions on a metafield. Metafield conditions work like any other: custom.clearance equals true, custom.release_year < 2025, or custom.brand is one of ….
Offers in a metaobject (Advanced). Create a metaobject definition such as offer with fields for tag, percentage, and minimum quantity. Link the definition to the function. The app syncs entries, and rules can read them, so a metaobject entry becomes a row in your discount table. Marketing adds a new offer by adding an entry.
Variations
- Customer or shop metafields. The function can read one shop metafield slot, for storewide values such as a sale multiplier.
- Variant-level pricing. Use a variant metafield when sizes or materials have different margins.
Limits to know
- Each function reads one product, one variant, and one shop metafield slot; choose the one that drives the offer.
- Metaobjects as rule data need the Advanced plan.