0
votes

I use the Order Printer app in Shopify to print my orders. I have edited the the template to suit my needs, however I am quiet new to Liquid code.

Based on the shipping postcode of the order, I need the template to return 1 of 3 labels - Rural, Major and Outer. I have a list of postcodes in the following format (this is a small portion for example):

Rural

2648, 2715, 2717-2719, 2731-2739, 3221-3334, 3342-3349, 3351-3352, 3357-3426, 3444-3688, 3691-3749, 3812-3909, 3921-3925, 3945-3974, 3979, 3984-3999


Major

1000-1935, 2000-2079, 2085-2107, 2109-2156, 2158, 2160-2172, 2174-2229, 2232-2249, 2557-2559, 2564-2567, 2740-2744, 2747-2751, 2759-2764, 2766-2774, 2776-2777, 2890-2897


Outer

7020-7049, 7054, 7109-7150, 7155-7171, 7173-7247, 7255-7257, 7330-7799

I'm unable to work out how to use the if statement for the purpose of identifying if the shipping postcode is a rural, major or outer postcode, without typing out every postcode between 7330 and 7799 etc.

Can anyone help?

1
This seemed to have worked for me: {% if shipping_address.zip >="4000" and shipping_address.zip <="4018" or shipping_address.zip >="4029" and shipping_address.zip <="4068" %} Z1 {% elsif shipping_address.zip >="1000" and shipping_address.zip <="1935" or shipping_address.zip >="2900" and shipping_address.zip <="2920" %} Z2 {% elsif shipping_address.zip >="2264" and shipping_address.zip <="2281" or shipping_address.zip >="2311" and shipping_address.zip <="2484" %} Z3 {% else %} ZU {% endif %}ryerye
If you were able to solve the problem, be sure to add it as an answer to your question as well. That way, anyone with a similar question in the future will be able to see that this problem was solved. :)Dave B

1 Answers

0
votes

First declare your arrays:

{% assign Rural= "2648, 2715, 2717-2719, 2731-2739, 3221-3334, ...." | split: ", " %}
{% assign Major= "1000-1935, 2000-2079, 2085-2107, 2109-2156,..." | split: ", " %}
{% assign Outer= "7020-7049, 7054, 7109-7150, 7155-7171,...." | split: ", " %}

Then declare a variable that you will use for the label

{% assign relatedLabel = ""%}

Implement the if logic

{% if Rural contains Order.PosteCode %}
{% assign relatedLabel = "rural" %}
{% endif %}
{% if Major contains Order.PosteCode %}
{% assign relatedLabel = "major" %}
{% endif %}
{% if Outer contains Order.PosteCode %} 
{% assign relatedLabel = "outer" %}
{% endif %}

Finally you can print it where you need it

This Poste Code belongs to {{relatedLabel}} area.