jquery - Shopify - Rewrite the Add to cart button code to send custom AJAX request that includes custom products
Solution:
If you want to limit inventory for a variant to the amount available or less, you have to do some work. First off, you know the product and its variant ID. You can use that to ask Shopify how much inventory is currently available, or, even easier, when you render the product in the first place using Liquid, you can also render out the inventory quantity.
With that number, you can inform the customer they cannot have 8 if there are only 7 in inventory. Has nothing to do with Shopify Ajax API calls.
It can get a little gnarly adding this level of control but in the end, Shopify Ajax calls are pretty simple, you get back a 200 OK or you don't. How you proceed with this is up to you. It sounds like you have the basics in place nicely, so carry on!
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.