Adding product Y automatically when clicking add to cart for product X

Hi!
May I know or get some help regarding adding a freebie product Y that shows up in the cart drawer when clicking on add-to-cart for product X?

An example is the image below where the second product is added automatically when a customer add the crystal hair to cart.

I’ve tried a few ways with the product ID through the const form but i think i may be adding it wrongly

thanks so much!

Hi @Stormmmneo ,

You can write a custom code which will watch the cart data and when it matched with your criteria and fire script to add free bee item.

you can use code provided in below URL to add freebie in account.

https://shopify.dev/docs/api/ajax/reference/cart

Hi,

To automatically add a free product to the cart, you can set up a Buy X Get Y offer in the BOGOS App. With this feature, when a customer clicks “Add to cart” for the main product, the free gift will be instantly added to the cart drawer without any manual action from the customer.

You can check out an example here:

Hello, @Stormmmneo

Yes, this is absolutely possible on Shopify.

What you’re seeing in the example (where product Y is automatically added when product X is added to the cart) is typically done using a buy X get Y (BOGO) or bundle logic, not just a simple product ID inside the form.

The best and safest way to achieve this, especially with cart drawers and AJAX carts, is by using a dedicated bundle/BOGO app like Wizio Bundle – Buy X Get Y. Automatically add Product Y when Product X is added to the cart.

Suppose your goal is to add product Y automatically when product X is added to the cart and show it in the cart drawer. Use a Buy X Get Y / bundle solution instead of custom product-ID logic.

Check the example:

Hi!

If you’re looking to automatically add Product Y as a free gift when a customer clicks Add to Cart for Product X, you can set this up with the Monk Free Gift, BOGO & Upsell app, available on the Shopify App Store.

Monk lets you configure Product X as the qualifying product and Product Y as the free gift, so adding X to the cart triggers Y automatically without the customer having to select it manually. If the customer removes Product X and the cart no longer qualifies, the free gift will automatically be removed as well.

The offer can be displayed in the cart drawer or cart page, and if you’re using Shopify Plus, you can also display the offer on the checkout page.

Hope this helps!

Yes, you can do this without custom code. You’d basically want an automatic add-on/bundle offer where adding product X also adds product Y to the cart, ideally with the freebie condition built into the offer.

If you’re trying to avoid messing around with product IDs and cart form code, CrossSell is worth checking out. It supports bundles and product-specific offers, so you can set up these kinds of X → Y combinations without building the logic yourself.

If you do want to handle it through code, you’d need to make sure the add-to-cart request adds both variant IDs rather than trying to pass the product ID through the form.

Honestly between the app route and custom code, it really depends on how many X→Y pairs you’re trying to run. If it’s like one or two products doing this, custom code with the Ajax Cart API is probably less overhead long term than paying monthly for a bundle app just for that one interaction. But if you’re planning a bunch of different trigger/gift combos across your catalog, then yeah an app makes way more sense so you’re not maintaining a pile of conditional logic yourself.

The variant ID thing Ananya mentioned is the part that trips people up most when going the code route, worth double checking that first since a lot of the “it’s not working” issues come down to that alone.