I’m looking for a way to apply a discount where a customer would get a percentage off a collection when they’re purchasing another item. For example: Get 10% off all wax when you purchase 1 (or more) Candle Making kits.
The ‘Buy X, Get Y’ function in Shopify discounts does not work, as it limits the discount to only affect the number of products I set as Y. For example: If Y is set to 1, buying 1 kit gives the customer a discount on 1 block of wax. If Y is set to 100, buying 1 kit only gives the customer a discount on wax once they hit 100 items (101 would give them a discount on 100, and then 1 would be full price).
I’m looking for a way to make it so customers can get a discount on all the wax they add to their order, no matter the quantity, as long as 1 candle making kit is in their cart; whether that is through an app or a discount code.
Please note: The way to set this discount needs to be FREE
I will be appreciative of any advice or information people can provide!
Solution 1: Shopify Scripts (Shopify Plus Only)
If you’re on Shopify Plus, you can use a Shopify Script to apply a discount dynamically to all wax items when at least one Candle Making Kit is in the cart.
DISCOUNT_PERCENTAGE = 10
TRIGGER_PRODUCT_ID = 123456789 # Replace with the Candle Making Kit Product ID
DISCOUNT_COLLECTION_ID = 987654321 # Replace with the Wax Collection ID
eligible = false
# Check if the trigger product is in the cart
Input.cart.line_items.each do |line_item|
if line_item.variant.product.id == TRIGGER_PRODUCT_ID
eligible = true
break
end
end
# Apply discount to wax collection items
if eligible
Input.cart.line_items.each do |line_item|
if line_item.variant.product.collections.map(&:id).include?(DISCOUNT_COLLECTION_ID)
line_item.change_line_price(line_item.line_price * (1 - DISCOUNT_PERCENTAGE / 100.0), message: "10% off with Candle Kit purchase")
end
end
end
Output.cart = Input.cart
Solution 2: Automatic Discounts & Draft Orders (Non-Plus)
Since Shopify’s native “Buy X, Get Y” discount doesn’t work the way you want, you can try the following workaround:
Steps:
Create an Automatic Discount
Go to Shopify Admin > Discounts.
Click Create Discount > Automatic Discount.
Set it to Percentage Discount (10%).
Apply it to the Wax Collection.
Under Minimum Purchase Requirements, select Specific Products and add Candle Making Kit.
Set it to apply to all items in the Wax Collection.
Use a Shopify App (FREE) if Needed
If Shopify’s discount settings don’t apply to all collection items, you can use the Shopify Functions (for eligible plans) or a free app like “Discount Ninja” (free tier available) to set up advanced discount rules.
Solution 3: Discount Code with Automatic Tagging
Another way is to:
Create a Discount Code (10% off Wax)
Use an automation tool (like Shopify Flow for Shopify Plus) to automatically tag customers who buy a Candle Making Kit.
Set the discount code to apply only if the customer has that tag.
Hope it helps, let me know if you need more assistance.
We do indeed have a Plus account, so I would love to try the first solution.
I just have a few questions:
Would this all be done through the ‘Script Editor’ app, and if so what template would I use?
Would it be possible to have the discount apply once 1 of any 3 products are added to the cart? (ie. When the customer adds the basic kit, the deluxe kit, or the silicone kit; these are three separate products, not different variants)
Would I just separate the product IDs with a comma?
I’ve tried implementing the code using one kit and the collection, just to see if it works and I received this error code in the console:
“[Error] undefined method ‘collections’ for #Product:0x7c83ebc70150
New Script:18:in Object.call
New Script:17”
Here is what the code currently looks like:
DISCOUNT_PERCENTAGE = 10
TRIGGER_PRODUCT_ID = 7020153405625 # Replace with the Candle Making Kit Product ID
DISCOUNT_COLLECTION_ID = 318430511289 # Replace with the Wax Collection ID
eligible = false
# Check if the trigger product is in the cart
Input.cart.line_items.each do |line_item|
if line_item.variant.product.id == TRIGGER_PRODUCT_ID
eligible = true
break
end
end
# Apply discount to wax collection items
if eligible
Input.cart.line_items.each do |line_item|
if line_item.variant.product.collections.map(&:id).include?(DISCOUNT_COLLECTION_ID)
line_item.change_line_price(line_item.line_price * (1 - DISCOUNT_PERCENTAGE / 100.0), message: "10% off with Candle Kit purchase")
end
end
end
Output.cart = Input.cart
I’m Ellie, a Shopify promotion expert with 4 years of experience!
Since you’re using Shopify Plus, custom code is an option, but I’d recommend it only if you have a developer on hand. Adding it yourself can lead to errors (like you tried above) and potential risks, like hack gifts if the code doesn’t cover all scenarios (and you don’t have any one backup to help you)
Are you using Shopify Plus? If using it, you can write a line item script that applies a 10% discount to all wax items when a candle-making kit is in the cart.
And if you’re on Basic/Advanced Shopify, use automatic discounts combined with a cart condition:
Create an automatic discount that applies 10% off wax products
Set a condition: Candle Making Kit must be in the cart
If Shopify’s automatic discounts don’t meet your needs, you can try a free app like Discount Ninja (has a free plan) to create dynamic cart-based discounts.