Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Re: Liquid coding - Automatically add a product to the cart if another product is in it.

Solved

Liquid coding - Automatically add a product to the cart if another product is in it.

seangerke
Excursionist
47 0 1

I am hoping this is just a simple line of code.

 

I want to add a specific product to the cart if another product is in it.

 

If {product has tag "Station"} is in cart 

Add {product x}

 

 

 

Accepted Solution (1)

oscprofessional
Shopify Partner
16116 2410 3126

This is an accepted solution.

Hello

 

By using below code first you can find that if the particular product is in cart:-

{% for item in cart.items %}
{% if item.product.id == "8223550921" %}
    <div><h1>Some text here!</h1> </div> <br> 
{% endif %}
{% endfor %}

 One you find the product then by using ajax we can add the another product to cart.

 

 

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free

View solution in original post

Replies 13 (13)

oscprofessional
Shopify Partner
16116 2410 3126

This is an accepted solution.

Hello

 

By using below code first you can find that if the particular product is in cart:-

{% for item in cart.items %}
{% if item.product.id == "8223550921" %}
    <div><h1>Some text here!</h1> </div> <br> 
{% endif %}
{% endfor %}

 One you find the product then by using ajax we can add the another product to cart.

 

 

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free
Jessica36
Shopify Partner
51 1 13

Hi. I'm trying to do something similar.

I want to have it so that if a particular product is in the cart it costs $10.

if any additional products are added to the cart, the price becomes 0.

Is this possible? It's just for one product. 

Thanks!

seangerke
Excursionist
47 0 1
Yes, not sure on coding, but I use the app Locksmith (expensive) that will
do it easy.

Im guessing it would be a code in your cart thats something like

{% if any product == cart)
Make product.price = $0.00

Maybe something like that?
Jessica36
Shopify Partner
51 1 13

Hm, I use locksmith on another site, didn't know it could do that. I do like that app and the customer service.

Thanks. Wonder if something less expensive can do it too...

 

Will test the code. 

seangerke
Excursionist
47 0 1

{% for item in cart.items %}
{% if item.product.id == "29056231440487" %}
jQuery.post('/cart/update.js',
{
quantity:1,
id: 6619002634270

});


This is what I came up with but still not working. Am I adding the wrong IDs? First picture goes to the top, 2nd pic is reference to product I want added.

 

 

code1.pngcode2.png

shwey
Visitor
1 0 0

Were you able to solve this? I'm trying to do something similar - some of our products ship in two boxes so I want to automatically add a second product to the cart when other specific products are added. The call to actually add a product to the cart isn't working for me either.

Jessica36
Shopify Partner
51 1 13

I got distracted since it wasn't a priority. If you figure it out, let me know. If I figure it out, I'll let you know. 

jess

seangerke
Excursionist
47 0 1
That sounds great, bc currently I have nothing to show for like 15+ hrs of my life I spent on this. I kinda gave up and made it part of the back office procedure. Instead of having it a separate cart item, its fulfilled in back office.
seangerke
Excursionist
47 0 1
Unfortunately I have nothing to show for this. I tried and tired and did not get anywhere. Sorry...

adam_bn
Shopify Partner
79 4 16

Another solution that doesn't require coding or editing liquid files is Gifter, which is an app that does this for you. It also lets you apply discounts, and create more complex rules.

 

There's a free trial here: https://apps.shopify.com/gifter-cart-auto-include

Dashergrooming
Tourist
10 1 16

Looking for same solution. I do came across this app https://bit.ly/3zD2VXb

But this doesnt work upto mark. sometimes it works sometimes doesnt. 

 

Is there any alternative you guys came up with?

Jessica36
Shopify Partner
51 1 13

I ultimately went with an app. I use Ultimate Special Offers. It's been great and Alex is really nice when you need help. 

Dashergrooming
Tourist
10 1 16

That's great app. But i think there are better functionality app than that

check them for auto add-to-cart:  Easygift      cart bot 

check them for upsell/cross sell popup immediately after pressing add to cart: product page upsell