This guide will walk you through implementing a customizable promotional popup that appears when customers add specific products to their cart. Perfect for offering free gifts, upsells, or special promotions! I've broken the code into sections, you could however download all the code and throw it straight in there without a care in the world. However, having a basic understanding of what each part of the code means is going to help massively.
How It Works
The script monitors the cart for changes
When the trigger product is added, it checks if:
- The free gift isn't already in the cart
- The user hasn't previously declined the offerIf conditions are met, the popup appears
Users can either:
- Add the free gift (redirects to cart)
- Decline the offer (popup won't appear again in this session)
Features
✨ Fully customizable appearance
🎯 Targeted product promotion
🔄 Single-session decline memory
📱 Responsive design
🎁 Automatic free gift addition
How to automatically add a free product to cart with a single purchase?
Shopify just loves to have you reliant on apps! The problem with apps is they cost money and will most likely slow your site down as well. Not good. Shopify's Buy X Get Y is a great discount, but it requires the customer to go and add their free gift, resulting in more clicks and increasing potential drop-off.
One solution is to utilize a pop-up that appears once the trigger product has been added. So today's your lucky day boys and gals, cos we're gonna do just that!
Create an automatic Buy X get Y discount code in Shopify. This way the discount will automatically apply when the item is added to the cart.
Add this code and customize.
Enjoy!

Step 1: Grab Your Code
Download your FREE Logo Ticker code…you're welcome!
This free download is provided “as is” without warranties of any kind. We make no guarantees regarding accessibility compliance. Use at your own discretion.
Step 2: Initial Setup
First, locate your theme's theme.liquid
file in your Shopify theme editor. Add the following configurable settings at the bottom of the page right before </body>
Step 3: Create the Popup HTML
The pop-up structure uses dynamic styling based on your settings:
Step 4: Add Cart Monitoring
This code watches for changes in the cart and shows the popup when appropriate:
Step 5: Handle the Free Gift Addition
Add this code to handle adding the free gift to cart:
Step 6: Customize for Your Store
To adapt this code for your store:
Change the
triggerProduct.title
to match your main product's exact titleUpdate the
freeGift
settings with your gift product's details:title
: Exact product titlehandle
: Product handle from URL: shopifystore.com/products/FREE-GIFT
Customize the popup appearance in the
popup
settings:Modify text content
Adjust colors to match your brand
Update button text