Discount function · Plan: Advanced
How do I discount accessories only when the matching main product is in the cart, and only as many as there are main products?
Link the items through a product or variant metafield, condition the accessory lines on that link, and use aggregates and a variable to cap the discounted quantity at the number of main products in the cart. This needs the Advanced plan, not Shopify Plus.
- Function typeDiscount
- Plan neededAdvanced
- Shopify PlusNot required
- Updated
What the shopper sees
They add two lamps. Any compatible bulbs they add are 25% off, up to two bulbs. A third bulb is full price. Remove a lamp and only one bulb stays discounted.
How the rule is built
- Link the products. Put a metafield on each bulb, for example
custom.fits_socket = E27, and the same on each lamp. Or store a list of compatible bulb variant ids on the lamp. - Data access. Select that product metafield for the function.
- Count the main products. Define a variable
lampsas the quantity sum of lines taggedlamp(or in the Lamps collection). - Rule. Product discount, line conditions
tag = bulb AND metafield fits_socket equals <the lamp's value>, target selection cheapest matching, target quantitylamps, value 25%.
The cap comes from the target quantity being driven by the variable, so the discount scales with the number of lamps and never beyond it.
Variations
- Several socket types in one cart. One rule per socket type, each with its own variable.
- Free instead of 25%. Set the value to 100%.
- Only when bought together for the first time. Add a customer segment on the discount’s eligibility.
Limits to know
- Variables are an Advanced plan feature.
- The match is by metafield value equality, so keep values normalized (
E27, notE 27on some products).