Shopify 售罄消息
Shopify Sold Out Message
当我们将产品的数量设置为 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 %}`
问题是即使有一种尺寸缺货而其他尺寸没有,它也会显示已售罄的消息。有没有办法检查并确保 所有 尺寸都已售罄?
您是否尝试过手册中的多项检查?
{% 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 %}
您可以只检查 product.available 属性:
product.available
Returns true if a product is available for purchase. Returns false if
all of the products variants' inventory_quantity values are zero or
less, and their inventory_policy is not set to "Allow users to
purchase this item, even if it is no longer in stock."
因此您可以使用例如:
{% if product.available == false %}
This item is currently sold out.
{% endif %}
当我们将产品的数量设置为 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 %}`
问题是即使有一种尺寸缺货而其他尺寸没有,它也会显示已售罄的消息。有没有办法检查并确保 所有 尺寸都已售罄?
您是否尝试过手册中的多项检查?
{% 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 %}
您可以只检查 product.available 属性:
product.available
Returns true if a product is available for purchase. Returns false if all of the products variants' inventory_quantity values are zero or less, and their inventory_policy is not set to "Allow users to purchase this item, even if it is no longer in stock."
因此您可以使用例如:
{% if product.available == false %}
This item is currently sold out.
{% endif %}