I would like to add a new function to the product details page that shows me the current quantity of the variant that is in stock.
I get this far with Liquid, only if another variant is selected, the display of the amount does not change,
Anyone of you have any ideas how I can do that?
This shows me the current variant, but does not change when I change the selection.
{% - for variant in product.variants -%}
{{current_variant.inventory_quantity}}
{% - endfor -%}
2
Answers
You can’t use Liquid for this. Liquid is just Shopify’s templating language and is only useful for the initial page render.
I know how to do this. You need to use vue so it‘s reactive on the front end, also each product with variants now has to be a collection. You will need to loop through the products in the collection and get the linked products with javascript.
So let‘s say you have a specific product and you have three versions of it, you would actually create three separate products.
The next thing to do is link them with liquid and javascript, so in your product.liquid file open a set of script tags and you would start it like this
This is just to get the ball rolling but you will need to handle quite a bit of other things and this is quite a large project.