商品购物车价格和比较价格重复

时间:2021-05-01 15:26:46

标签: shopify liquid

如果我有多个变体,价格和比较价格重复,比如我有黑色和高个变体,那么每个变体旁边的价格是 200 美元。

如何只显示一次?

这是我的代码:

<块引用>

{% 分配 beforePrice = priceCompare |次数:item.quantity %}

{{ item.variant.options[forloop.index0] }} {{ item.product.price[forloop.index0] }}

{% if item.product.compare_at_price > item.product.price %} {{ beforePrice |钱}} {% endif %}

1 个答案:

答案 0 :(得分:1)

如果您只希望它在循环的第一次迭代中输出一次并假设您正在遍历变体(这可能有助于查看您的所有循环),您可以使用 forloop.first


{% if forloop.first %}
  {{ item.variant.options[forloop.index0] }} {{ item.product.price[forloop.index0] }}
{% endif %}

或者你可能会发现你可以省去循环并做

{{ item.variant.options.first }} {{ item.product.price.first }}