How to convert string value to integer in Shopify

convert string to integer in shopify variable

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 🙏

If this help you then.. Can you buy a Cup of Coffee for me by nst webcreation paypal--OR-- nst webcreation blog coffee cup

Published by

NST

Myself Narender Singh Thakur ( NST ) and i share my Experience/Knowledge and Tricks for folks and beginners to solve their issues while making websites through this Planet.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to Chat