【问题标题】:Shopify show stock when quantity is lower than 2Shopify 在数量低于 2 时显示库存
【发布时间】:2021-02-05 11:43:00
【问题描述】:

我已为我的 shopify 商店构建了此代码 sn-p,以在下拉字段中显示更多信息。随着更改,状态现在也显示在尺寸选择旁边。有货或售罄。不幸的是,我无法解决如果变体上的库存数量小于 2,那么系统会显示文本。只有 1 个可用。

 <select id="product-select-{{ product.id }}" name="id" class="main_select">
                  {% for variant in product.variants %}

                    {% if variant.available %}
                  <option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} value="{{ variant.id }}">{{ variant.title }} <span>Verfügbar: {{ variant.inventory_quantity}}</span></option>

                    {% else %}
                      <option disabled="disabled">
                        {{ variant.title }} - {{'products.product.sold_out' | t }}
                      </option>

                    {% endif %}

                  {% endfor %}
                </select>

当前

【问题讨论】:

  • 如果有一个数量不需要显示,如果数量为0则缺货。那么它的好处是什么
  • 更多是为了增加只提供一次的产品的销量。例如,如果 34 码仅售一次,客户更有可能在该码完全售罄之前购买。
  • 我可以使用&lt;span&gt;Verfügbar: {{ variant.inventory_quantity}} 调整代码,但它会显示所有可用变体的数量,但我只想显示那些数量少于两个的产品跨度>

标签: javascript html shopify liquid


【解决方案1】:

您应该能够在选项本身中添加另一个 if 语句,如下所示:

<select id="product-select-{{ product.id }}" name="id" class="main_select">
  {% for variant in product.variants %}
    {% if variant.available %}
      <option
        {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %}
        value="{{ variant.id }}"
      >
          {{ variant.title }} <span>Verfügbar {% if variant.inventory_quantity < 2 %}: ONLY 1 AVAILABLE{% endif %}</span>
      </option>

    {% else %}
      <option disabled="disabled">
        {{ variant.title }} - {{'products.product.sold_out' | t }}
      </option>

    {% endif %}

  {% endfor %}
</select>

【讨论】:

    猜你喜欢
    • 2019-05-13
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 2018-09-23
    相关资源
    最近更新 更多