Here are some common questions related to this :-
- How to convert assigned variable string value to integer ?
- String value variable to integer variable in Shopify ?
- String value to integer value using variable.
- variable of string value to integer ?
Here is the solution for that questions..
Look at bottom code… this is a code to show the sold out badge .. if all the variants quantity is 0 of a product on collection page.
{% if collection.title contains "Best Sellers" %}
{% assign total_qnt = 0 %}
{%for variant in product.variants %}
{% capture i %}{{ total_qnt | plus:variant.inventory_quantity }}{%endcapture%}
{% assign total_qnt = i %}
{%endfor%}
{% assign total_qnt1 = total_qnt | plus:0 %}
{% if total_qnt1 < 1 %}
<div class="soldout">SOLD OUT</div>
{% endif %}
{% endif %}
As highlighted above code… In your script just add
| plus:0
in your variable and this will compare now as integer..
you need this when you want to compare the variable with operators…
as i compared above to check if the product quantity is < than 1.
Thanks 🙏