skip to Main Content

I am trying to get the weight of a product based on what was entered for that product as weight. From there use an IF statement to show the shipping fee or Free Shipping.

Here is the code I currently have but it’s not working at all.

 {% if currentvariant.weight == '99' %}
 FREE WORLDWIDE SHIPPING
 {% endif %}

If a product has a weight entered as 99, it’s set for free shipping. So I am trying to get it to show Free Worldwide Shipping.

The template being used is Debut.
The file I am placing the code in is the product-template.liquid

I have also tried to assign a variable to it. For example:

 {% assign the_weight = currentvariant.weight %}

 {% if the_weight == '99' %}
 FREE WORLDWIDE SHIPPING
 {% endif %}

I have also tried using ‘99.0’ just in case it is putting the .0 in the variable and that does not work either.

I have also tried variant.weight and that does not work either.

2

Answers


  1. Chosen as BEST ANSWER

    I figured it out. Just in case anyone want's to do this, here is the code that I am using.

        {% assign skip = '0' %}
        {% for variant in product.variants %}
        {% assign theweight = variant.weight | weight_with_unit %}
        {% if skip == '0' %}
        {% if theweight == '99.0 lb' %}
        <span style="font-size:18px; color:red;"><b>FREE WORLDWIDE SHIPPING</b></span>
        {% endif %}
        {% assign skip = '1' %}
        {% endif %}
        {% endfor %}
    

    That's based on the fact that I have the weight on some products set to 99.0 lbs and set that weight to Free Shipping. You will need to change the 99.0 lb to what ever weight you have set to Free Shipping and if you don't have your weight set in lbs change that to your weight as well. Example: 99.0 kg

    The Skip is in there because it will show Free Shipping for every variant you have for that product and we only want to show it once.


  2. Try to use in product-template file-

    {{ product.variants.first.weight | weight_with_unit }}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search