I want to show inventory quantity less than or equal to 3 and using this code but it is showing me the sold out only.
{% assign current_variant = product.variants.first %}
<div class="inventoryNote form__label">
{% if current_variant.inventory_quantity > 0 and current_variant.inventory_quantity <= 3 %}
<p style="color: #D0DF00; text-align:center">ONLY {{ current_variant.inventory_quantity }} LEFT</p>
{% elsif current_variant.inventory_quantity <= 0 %}
<p style="color: #D0DF00; text-align:center">SOLD OUT</p>
{% else %}
<!-- Optionally handle cases where inventory is greater than 3 -->
<p style="color: #D0DF00; text-align:center">In stock</p>
{% endif %}
</div>
1 Like
{% assign current_variant = product.selected_or_first_available_variant %}
{% if current_variant.inventory_management == "shopify" %}
{% if current_variant.inventory_quantity > 0 and current_variant.inventory_quantity <= 3 %}
ONLY {{ current_variant.inventory_quantity }} LEFT
{% elsif current_variant.inventory_quantity <= 0 %}
SOLD OUT
{% else %}
In stock
{% endif %}
{% else %}
{% endif %}
Can you try this code @saeedahmed0174
Picking the inventory of first avalaible variant
1 Like
{% assign first_available_variant = null %}
{% for variant in product.variants %}
{% if variant.inventory_quantity > 0 %}
{% assign first_available_variant = variant %}
{% break %}
{% endif %}
{% endfor %}
{% if first_available_variant %}
{% if first_available_variant.inventory_quantity <= 3 %}
ONLY {{ first_available_variant.inventory_quantity }} LEFT
{% else %}
In stock
{% endif %}
{% else %}
SOLD OUT
{% endif %}
My questions was about this It has same issue picking inventory for first avalaible variant not the selected one
But this code pick the inventory of only first available variant and dono change when i select another varinat