【问题标题】:Shopify Sold Out MessageShopify 售罄消息
【发布时间】:2016-09-09 13:16:19
【问题描述】:

当我们将产品的数量设置为 0 时,我试图显示一条已售罄的消息。这段液体代码有点用:

`{% assign variantQuantity = product.variants | map: 'inventory_quantity' | sort %}
{% if variantQuantity[0] < 1 %}
<strong><p style="color: #B21F1F;">This item is currently sold out.</p></strong>
{% else %}
{% endif %}`



问题是即使一种尺码缺货而其他尺码也没有,它会显示已售罄消息。有没有办法检查并确保 所有 尺寸已售罄?

【问题讨论】:

    标签: shopify


    【解决方案1】:

    你可以只检查 product.available 属性:

    product.available

    如果产品可供购买,则返回 true。如果返回 false 所有产品变体的inventory_quantity 值均为零或 更少,并且他们的 inventory_policy 未设置为“允许用户 购买此商品,即使它不再有库存。”

    所以你可以使用例如:

    {% if product.available == false %}
      This item is currently sold out.
    {% endif %}
    

    【讨论】:

    • 就是这样!谢谢!
    【解决方案2】:

    您尝试过手册中的多重检查吗?

    {% if variant.inventory_quantity <= 0 and variant.available and variant.inventory_management != '' %}
    

    所以例子是:

    {% assign variantQuantity = product.variants | map: 'inventory_quantity' | sort %}
    {% if variant.inventory_quantity <= 0 and variant.available and variant.inventory_management != '' %}
    <strong><p style="color: #B21F1F;">This item is currently sold out.</p></strong>
    {% else %}
    {% endif %}
    

    【讨论】:

    • 谢谢!出于某种原因,它没有选择 variant.inventory_quantity &lt;= 0 部分。它以前与 if variantQuantity[0] &lt; 1 % 一起工作,但同样,即使其他一些尺寸有库存,它也会显示。
    猜你喜欢
    • 2018-03-13
    • 2020-05-19
    • 2021-04-26
    • 1970-01-01
    • 2023-03-22
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    相关资源
    最近更新 更多