Display each variation and current stock level in the description of the product?

How can i accomplish the following:

Display each variation and current stock level in the description of the product

Example:

Product A has 3 variations

  1. Choice a - 10 stock

  2. Choice b - 0 stock

  3. Choice c - 5 stock

In the Product description how can i show this current stock list?

Hi @crowshead ,

Please add code:


          {%- for variant in product.variants -%}
            - {{ variant.title }} - {{ variant.inventory_quantity }} stock
          {%- endfor -%}

Hope it helps!

1 Like

worked perfect!

OK, i figured out where to add that code.

Works great, but can i restrict it to only show for products with certain product tags?

Hi @crowshead ,

Please change code:

{% if product.tags contains 'tag product' %}

  {%- for variant in product.variants -%}
    - {{ variant.title }} - {{ variant.inventory_quantity }} stock
  {%- endfor -%}

{% endif %}

If it helped you solve your issue, please mark it as a solution. Thank you and good luck.

1 Like

Couple more things:

  1. only display for certain collections

  2. only display those variantions that are >0

Hi @crowshead ,

Please change code:

{% if product.tags contains 'tag product' %}
  {% for collection in product.collections %}
    {% if collection.title == 'Cart Bump' %}
      
        {%- for variant in product.variants -%}
          - {{ variant.title }} - {{ variant.inventory_quantity }} stock
        {%- endfor -%}
      

      {% break %}
    {% endif %}
  {% endfor %}
{% endif %}

Thats perfect, same code, but only display those variantions that are >0

Hi @crowshead ,

Please change code:

{% if product.tags contains 'tag product' %}
  {% for collection in product.collections %}
    {% if collection.title == 'Cart Bump' %}
      
        {%- for variant in product.variants -%}
          {%- if variant.inventory_quantity > 0 -%}
          - {{ variant.title }} - {{ variant.inventory_quantity }} stock
          {%- endif -%}
        {%- endfor -%}
      

      {% break %}
    {% endif %}
  {% endfor %}
{% endif %}

you rock!

1 Like

Hi @crowshead

In case you still looking for a solution to your question, you can check out this app to display your inventory quantity on your product page.

Best regards,

1 Like