2013-11-20 34 views
2

我想检查购物车中的商品是否属于集合的一部分(或者是否具有特定标记)。Shopify:如何查看购物车中的商品是否具有特定标记

这里是我的“企图”在尝试检查是否有产品

{% for item in cart.items %}  
{% if item.product.collections == "SampleProduct" %} 
    <p>Enjoy your Product</p> 
{% endif %} 
{% endfor %} 

任何帮助将不胜感激。

感谢

回答

6

如果要检查,如果你的产品是在特定集合,你需要这样的事:

{% for item in cart.items %} 
    {% assign found_collection = false %} 
    {% for collection in item.product.collections %} 
    {% if found_collection == false and collection.title == 'SampleProduct' %} 
     {% assign found_collection = true %} 
    {% endif %} 
    {% endfor %} 
    {% if found_collection %} 
    <p>Enjoy your Product</p> 
    {% endif %} 
{% endfor %} 

或者,如果您要检查标签,使用此:

{% for item in cart.items %} 
    {% if item.product.tags contains 'SampleProduct' %} 
    <p>Enjoy your Product</p> 
    {% endif %} 
{% endfor %} 

欲了解更多信息,请参阅contains operator的Shopify wiki页面。

+0

非常感谢您的帮助! – MrBoots

相关问题