首页 > 解决方案 > 如果在 shopify 中变体数量少于两个,则显示变体标题

问题描述

嗨,我在 Shopify 网站上工作。我想要实现的是从我的收藏页面中隐藏缺货产品的变体标题。“我已经完成了”所以现在我要尝试的是。显示数量超过 2 的产品的变体标题。“这是卡住的部分”这是我的代码

        {%- assign empty_list = true -%}
{%- for variant in product.variants -%}
  {%- comment -%}Skip the variant if it's not available{%- endcomment -%}
  {%- unless variant.available -%}
    {%- continue -%}
  {%- endunless -%}

  {%- comment -%}Print a comma unless our list is empty{%- endcomment -%}
  {%- unless empty_list -%},{%- endunless -%}
  {%- assign empty_list = false -%}

  {%- comment -%}Now print our new entry{%- endcomment -%}
    
  <span class="variant-name"> {{ variant.title }}</span>
   
{%- endfor -%}
      

标签: shopifyshopify-template

解决方案


通过使用以下代码,您可以获得数量超过 2 的产品标题。

{% for variant in product.variants %}

    {% if variant.inventory_quantity > 2 %}
        {{- variant.title -}} <br>
    {% endif %}

{% endfor %}

推荐阅读