How can I display inventory quantity for product variants?

I’ve been trying to get this value (https://help.shopify.com/en/themes/liquid/objects/variant#variant-inventory_quantity) to show on a collections page.

I’ve setup the products with a bunch of variants, updated the quantities for each manually and have doubled checked they are saved. I even waited about 8 hours to make sure it wasn’t some delay in populating values or something. But I do not see inventory_quantity as a field in my product.liquid or collection.liquid pages. When I print the JSON for an individual product, here is what I get (removed the values from most of it):

{
  "id": ,
  "title": "",
  "option1": "",
  "option2": "",
  "option3": null,
  "sku": "",
  "requires_shipping": true,
  "taxable": true,
  "featured_image": null,
  "available": true,
  "name": "",
  "public_title": "",
  "options": ["Small", "Black"],
  "price": 45600,
  "weight": 0,
  "compare_at_price": null,
  "inventory_management": "shopify",
  "barcode": ""
}

I don’t see inventory_quantity as a field, so I’m wondering if I’m not using the right query or something for these products, and if so, how do I change the fields I get back?

I’ve also looked at the product.js responses, and I get the same values in JS as appear from the liquid template. From everything I’ve searched, this doesn’t seem to be an issue for a lot of people so I’m wondering what I’ve missed.

Thanks!

Looks like the variant.inventory_quantity is hidden from the JSON filter on liquid – printing this worked:

<div><pre>QUANT: {{ current_variant.inventory_quantity }}</pre></div> ---> QUANT: 12

Confusing!

1 Like

If we can use {{ product.variants | json }}, look like there is no performance issue. Let’s say you use a for loop to get the inventory quantity for all variants in a collection. Is it going to be super slow?