Hide Variant Quantity on Product Page When Continue to Sell is Checked

Hi all,

Would appreciate some help, I am trying to manipulate some code so I can enable product variant quantities on our product pages but only show the quantities for variants that are tracked and “continue to sell when out of stock” is unchecked. The former is already used in the code, but the latter needs to be inserted.

{% if section.settings.stock_enable %}
              - {% if current_variant.inventory_management %}
                      {% if current_variant.inventory_quantity < 10 and current_variant.inventory_quantity > 0 %}
                        {% assign qty = current_variant.inventory_quantity %}
                        {{ 'products.product.stock_available' | t: count: qty }}
                      {% elsif current_variant.inventory_quantity == 0 or current_variant.inventory_quantity < 0 and current_variant.incoming %}
                        {% if current_variant.available %}
                          {% assign date = current_variant.next_incoming_date | date: "%B %-d, %Y" %}
                          {{ 'products.product.will_not_ship_until' | t: date: date  }}
                        {% else %}
                          {% assign date = current_variant.next_incoming_date | date: "%B %-d, %Y" %}
                          {{ 'products.product.will_be_in_stock_after' | t: date: date  }}
                        {% endif %}
                      {% endif %}
                    {% endif %}
                
                
              

            {% endif %}

I have identified the variant object required to apply to the code but struggling to insert it correctly:

variant.inventory_policy

Returns the string continue if the “Allow users to purchase this item, even if it is no longer in stock.” checkbox is checked in the variant options in the Admin. Returns deny if it is unchecked.

Many thanks,

Mike

Ps. I have looked for the solution on the forum so apologies if this has been done before.

Merchants wanting this customization integrated into their theme can contact me with store detail to get pricing by forum PM or using my email in my forum signature.

To NOT do something when the policy is CONTINUE

{% unless variant.inventory_policy == "continue" %}
 {% comment %}Place conditional logic below this line{% endcomment %}
{% endunless %}

To do something when the policy is CONTINUE

{% if variant.inventory_policy == "continue" %}
 {% comment %}Place conditional logic below this line{% endcomment %}
{% endif %}

To do something when the policy IS NOT continue

{% if variant.inventory_policy != "continue" %}
 {% comment %}Place conditional logic below this line{% endcomment %}
{% endif %}

To do something when the policy is DENY , which is the opposite of continue

{% if variant.inventory_policy == "deny" %}
 {% comment %}Place conditional logic below this line{% endcomment %}
{% endif %}
1 Like

Hi Paul,

Thanks for your assistance.

“To do something when the policy is CONTINUE” was the answer for my needs.

For anyone else, this is the revised code so you can see where this was added in

{% if section.settings.stock_enable %}
              - {% if current_variant.inventory_management %}
                      {% if current_variant.inventory_quantity < 10 and current_variant.inventory_quantity > 0 %}
                        {% assign qty = current_variant.inventory_quantity %}
                        {{ 'products.product.stock_available' | t: count: qty }}
                      {% elsif current_variant.inventory_quantity == 0 or current_variant.inventory_quantity < 0 and current_variant.incoming %}
                        {% if current_variant.available %}
                          {% assign date = current_variant.next_incoming_date | date: "%B %-d, %Y" %}
                          {{ 'products.product.will_not_ship_until' | t: date: date  }}
                        {% else %}
                          {% assign date = current_variant.next_incoming_date | date: "%B %-d, %Y" %}
                          {{ 'products.product.will_be_in_stock_after' | t: date: date  }}
                        {% endif %}
                      {% endif %}
                    {% endif %}
                
                
              

            {% endif %}
1 Like