Can I add specific product into cart using Script Editor?

Sanket_Patel
Shopify Partner
6 0 0

Basically I am trying to give a free product on X amount of purshase. I have make it possible using Cart API. But in some cases it do not insert that product because it works in javascript, which may not execute completely due to slow connection or etc... or Even customer may set quantity 0 before checkout. So I would like to add code in Script Editor to insert that special Free Product in order of more than x amount. 

I have working solution using Cart API but out of 50 orders 2 or 3 orders do not contain that free product. So I guess, it will be 100% if I use Script Editor to insert free product into cart items.
 

Freelancer | Software Developer | Coder | sanket972528@gmail.com | https://sannket.com
0 Likes
Jason
Shopify Expert
10296 146 1949

Hey Sanket,

Shopify Scripts can not add items to the cart.

You'll need to look into ways to make you current process more reliable. What steps are you taking to ensure the product is in the cart before moving to checkout?

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
Sanket_Patel
Shopify Partner
6 0 0

I have write code in javascript to add/update cart with that free product on Each time when Customer Add New Product in cart. I have write same code on cart page that check cart items and total amount. If it does not find free product then Add/Update it. 

If user delete that free item (price set to $0) then cart page is refresh and my code on cart page again execute which add thre free product again.

Should I write same code on checkout page ? to ensure that Free Product in available in cart?

Freelancer | Software Developer | Coder | sanket972528@gmail.com | https://sannket.com
0 Likes
Jason
Shopify Expert
10296 146 1949

You could add some JavaScript to the checkout.liquid. You'll need to make sure you maintain and support that code if you do since the checkout will be upgraded regularly.

If your JavaScript code is not working in the cart it sounds like you'll still need to fix those.

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes