简体   繁体   English

Shopify Liquid如果声明

[英]Shopify Liquid if statement

I use the Order Printer app in Shopify to print my orders. 我使用Shopify中的订单打印机应用程序来打印我的订单。 I have edited the the template to suit my needs, however I am quiet new to Liquid code. 我已经根据自己的需要编辑了模板,但是我对Liquid代码不熟悉。

Based on the shipping postcode of the order, I need the template to return 1 of 3 labels - Rural, Major and Outer. 根据订单的运输邮政编码,我需要模板来返回3个标签中的1个-农村,主要和外部。 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 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 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 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. 我无法弄清楚如何使用if statement来识别运输的邮政编码是ruralmajor还是outer邮政编码,而无需在7330至7799之间输入每个邮政编码。

Can anyone help? 有人可以帮忙吗?

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逻辑

{% 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM