Liquid, JavaScript, themes, sales channels
Hi All,
I am pretty new to shopify and liquid. I am trying to build some xml using some liquid variables and have it all except the shipping method and the product cost.
My shipping method is based on total weight in pounds. This is what i attempted but does not seem to work as it is always setting to FEDEX
{% assign: total_weight = 0.000 %}
{% for line in line_items %}
{% assign total_weight = total_weight | plus: line.quantity | times: line.grams %} {% endfor %}
{% assign total_weight = total_weight | times: .00220462262185%}
//I can see here that the weight seems to calculate correct. I think my case statement maybe isnt right
{% case {total_weight} %}
{% when total_weight <= .98 %}
{% assign : shipping_method = 'USPS-First Class' %}
{% when {total_weight} <= 2 %}
{% assign : shipping_method = ' USPS-priority' %}
{% else %}
{% assign : shipping_method = 'FEDEX' %}
{% endcase %}
<ship_method>{{shipping_method}}</ship_method>
My other issue is how can I get product costs? My distributor requires for each order I send the cost I pay. I have this in my shopify products but can't find where to get it from liquid.
Thanks for any assistance
Solved! Go to the solution
This is an accepted solution.
There are couple of things I do not like in your code.
I'd do it like:
{% assign: total_weight = 0.000 %}
{% for line in line_items %}
{% assign line_weight = line.quantity | times: line.grams %}
{% assign total_weight = total_weight | plus: line_weight %}
{% endfor %}
{% assign total_weight = total_weight | times: .00220462262185%}
{% if total_weight <= .98 %}
{% assign shipping_method = 'USPS-First Class' %}
{% elsif total_weight <= 2 %}
{% assign shipping_method = ' USPS-priority' %}
{% else %}
{% assign shipping_method = 'FEDEX' %}
{% endif %}
<div class=ship_method>{{shipping_method}}</div>
This is an accepted solution.
There are couple of things I do not like in your code.
I'd do it like:
{% assign: total_weight = 0.000 %}
{% for line in line_items %}
{% assign line_weight = line.quantity | times: line.grams %}
{% assign total_weight = total_weight | plus: line_weight %}
{% endfor %}
{% assign total_weight = total_weight | times: .00220462262185%}
{% if total_weight <= .98 %}
{% assign shipping_method = 'USPS-First Class' %}
{% elsif total_weight <= 2 %}
{% assign shipping_method = ' USPS-priority' %}
{% else %}
{% assign shipping_method = 'FEDEX' %}
{% endif %}
<div class=ship_method>{{shipping_method}}</div>
Also, AFAIK variant cost field is not available in liquid.
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024