ruby - Shopify Script - Get a free X product when you spend Y amount
I'm searching all over the internet for a solution, and I hope you guys help me with that. I want to do a shopify script that automatically add a specific free product if cart is over a specific amount (100$ for ex). All i've find online is X% discount if cart is over $Y, but I want to add an existing product. Is there a way to do it ? Thanks in advance
Answer
Solution:
You could do this with the shopify Ajax API (https://help.shopify.com/themes/development/getting-started/using-ajax-api (https://help.shopify.com/themes/development/getting-started/using-ajax-api)).
With this API you can make a request to the cartGET /cart.js
and get back thetotal_price
. You can write some logic to say if that is > 100$ then post X product.
You can post a product to the cart with the Ajax API as wellPOST /cart/add.js
We wrote a little post on adding products to the cart with the Ajax API if you want to reference an example ajax request http://www.codeshopify.com/blog_posts/adding-to-cart-with-ajax (http://www.codeshopify.com/blog_posts/adding-to-cart-with-ajax)
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.