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

Topic summary

A user seeks help implementing an automatic freebie feature where adding product X to cart triggers product Y to be added automatically. They provided a screenshot example showing a second product appearing in the cart drawer when a customer adds a crystal hair product.

Current Status:

  • User attempted implementation using product ID through a const form but suspects incorrect implementation
  • No working solution achieved yet

Suggested Solution:
Another participant recommended:

  • Writing custom code to monitor cart data
  • Triggering a script when specific criteria are met
  • Using Shopify’s AJAX Cart API for adding the freebie item
  • Referenced official Shopify documentation for implementation guidance

The discussion remains open with no confirmed resolution or working code provided.

Summarized with AI on November 1. AI used: claude-sonnet-4-5-20250929.

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!

1 Like

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: