A Shopify Plus merchant seeks to offer 10% off all wax products when customers purchase any candle-making kit, with unlimited wax items eligible for the discount. The built-in ‘Buy X, Get Y’ discount doesn’t work because it caps the discounted quantity.
Proposed Solutions:
For Shopify Plus users:
Custom Shopify Script using the Script Editor app to dynamically apply discounts when trigger products are in cart
Automatic discounts with cart conditions (percentage discount on wax collection, requiring candle kit as minimum purchase)
Implementation Challenges:
The merchant attempted the script solution but encountered an error: undefined method 'collections' on line 18
Questions remain about supporting multiple trigger products (3 different kit variants) and proper script template selection
Alternative Approaches:
Third-party apps like BOGOS (offers gift slider popup for discounted wax items)
Discount Ninja app with free tier for dynamic cart-based discounts
Current Status:
The discussion remains unresolved. The original code provider acknowledged the error requires admin-level analysis but hasn’t provided a fix. The merchant is awaiting working code or clearer implementation guidance for the automatic discount method.
Summarized with AI on October 30.
AI used: claude-sonnet-4-5-20250929.
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.
@DBAdam , if you’re still looking for a solution and don’t want to hire a developer, I would suggest you take a look at the Discount Bot app.
The app has multi-tier BOGO discounts with built in bulk codes generation support. But more to your point, it lets you discount up to the Buy Y quantity. Here’s a screenshot of the configuration:
Unfortunately Shopify’s built-in “Buy X, Get Y” really can’t handle unlimited discounted items — it always needs a fixed Y quantity. If you want the discount to apply to all wax items whenever a kit is in the cart, the only free workaround is to use automatic discounts with conditions:
Create an automatic percentage discount (10%).
Set the applies to section to your wax collection.
In the minimum requirements section, choose “Customer must purchase specific products” and select your candle-making kit(s).
This basically tells Shopify: “Only apply 10% off this collection if the cart also has one of these products.” There’s no limit on how many wax items get discounted.
It’s not as flexible as a full BOGO app, but for your use case it usually works without needing a paid app.