【发布时间】:2016-09-06 12:29:11
【问题描述】:
我需要在我的购物车上创建一个 IF 语句脚本,它会根据购物车中的数量显示不同的文本。目前我只有两个选择。如果别的。我如何制作几个在特定金额上发生变化的 IF 语句?
到目前为止,我已经做了这个,它只适用于低于/超过 1000 的金额:
{% assign totalCart = 0 %}
{% for item in cart.items %}
{% assign totalCart = totalCart | plus:item.totalCart_raw %}
{% endfor %}
{% comment %}
If the amount
{% endcomment %}
{% if totalCart >= 1000 %}
Volume Discount 20%
{%else%}
Volume Discount available 30%
{%endif%}
【问题讨论】:
-
您可以使用
case+when语句吗?或者可能是链if+elsif+else取决于你到底想要做什么。编辑:Documentation -
@UnholySheep case+when 语句是最好的选择,当我需要 5 个不同的文本时,取决于数量?
-
最有可能,尽管这取决于。
case+when只能进行相等比较,不能进行更大/更小的比较。在这种情况下,您将不得不使用if+elsif+else -
好的,我需要 5 个不同的更大/更小比较。如何使用 5 种不同的 if + elseif + else 语句编写代码?你能帮我举个例子@UnholySheep吗?
标签: shopping-cart liquid