Apply Discount to Collection When Purchasing Another Item

Hi there,

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!

Hi @DBAdam ,

There are three solutions to handle this:

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.

Regards,

2 Likes

Thank you for the response!

We do indeed have a Plus account, so I would love to try the first solution.

I just have a few questions:

  1. Would this all be done through the ‘Script Editor’ app, and if so what template would I use?
  2. 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

Hi @DBAdam :blush: ,

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)

If you don’t want to hire a developer, you can still achieve a similar effect with the BOGOS app, a powerful Shopify promotion app!

**:blue_heart: How it works:**Customers add (at least) 1 bundle kit to their cart → a gift slider will pop up → they can add to the cart the available waxes.

*All wax items will be 10% off and automatically added to their cart.

*It will look like this on your store:

:blue_heart: How it can effectively help you:

  • More easily inform customers that you’re offering a hot deal when they buy your kit.
  • Streamline the shopping experience → customers don’t have to search for and add wax to cart manually by themselves
  • Promote wax as gift, making it feel more enticing + not forcing them to buy
  • Save a lot of your time and provide fraud protection for your store + 24/5 premium support.
  • One app for gifts, bundles, upsells, and discounts!

The setup screen would look like this:

![Screenshot 2025-03-19 103008.png|1060x895](upload://8W8op1fjqWdZuAQWVkmwJKup0Lj.png)


:glowing_star: You can try it for 7 days free to see how it works. And if you need any help, even with small things, just let me know—I’m always here to help!

Appreciate it if you could Like and Accept as Solution if my answer was helpful! :growing_heart:

Hi @DBAdam

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.

1 Like

Thanks @Promer-Aila

Our store is Shopify Plus, so I could do either of those first two solutions.

How would I go about writing that script?

How do I use automatic discounts and a cart condition?

Thank you,
Adam

1 Like

@Dotsquares Any assistance with the above issues would be greatly appreciated

Hi @DBAdam ,

Need to analyse the admin.

The code which I provided you is test-based. You can reach me if you need more help.

Regards,

You can try this
Automatic Discount + Cart Condition (Non-Script Method)

If you prefer using automatic discounts, follow these steps:

  1. Go to Shopify Admin > Discounts > Create Discount.
  2. Select automatic discount and set it as:
    • Type: Percentage (10%)
    • Applies to: Specific collections (Select your Wax collection)
    • Minimum requirement: Select Specific product(s) and add the Candle Making Kit.
  3. Save & test, this will only apply when the Candle Making Kit is in the cart.