Warm tip: This article is reproduced from serverfault.com, please click

html-如何根据shopify中的标签和可用库存显示不同的交货消息?

(html - How to display different delivery messages depending on tag and available stock in shopify?)

发布于 2020-12-15 17:58:07

我希望有人可以帮助我。我想显示设置为超售的某些带标签物品的交货状态。

首先,我正在查看产品是否带有“香水”标签,然后库存是否高于或低于0

我已经从堆栈上的几个示例中拼凑了这段代码(对此非常新)

{% if product.tags contains 'perfume' and current_variant.inventory_quantity <=0 %}
  <div>No inventory, customer allowed to order but has long wait' = Out of Stock please allow 20-30 days for delivery</div>
 
{% elsif product.tags contains 'perfume' and current_variant.inventory_quantity <=1 %}
  <div>No inventory, but customer allowed to order' = Order now for delivery within 7 days</div>
 
{% else %}
  <div>Items in stock' = We have {{ current_variant.inventory_quantity }} in stock for delivery in 4-6 days.</div>
 
{% endif %}

当我刷新产品时,得到的所有其他输出都显示出库存为负,我尝试了不同的标签,还尝试了...

{% if collection.handle== 'perfume' %}

感谢KOOSA


这是你的代码的编辑版本

它在我的产品页面上显示了这两个规则的输出

        <div class="productShippingInformation">
          
          {% if product.tags contains 'Discount Enabled' and current_variant.inventory_policy == 'continue' %}
          
         {% elsif current_variant.inventory_quantity >= 1 %}
           Delivered in 4-6 days.
         {% endif %}
         {% if current_variant.inventory_quantity <= 0 %}
          <b>Delivered in 10-14 days.</b>
             {% endif %}
          
               

          {% if product.tags contains 'Perfume & Aftershave' and current_variant.inventory_policy == 'continue' %}

    {% if current_variant.inventory_quantity <= 0 %}
      <div><b>Delivery in 2021.</b> please allow 20-30 days for delivery</div>
 
    {% elsif current_variant.inventory_quantity >= 1 %}
      <div>Order now for delivery within 7 days</div>

    {% endif %}

{% else %}
  <div>in stock for delivery in 4-6 days.</div>

{% endif %}

我认为这是答案,感谢你的帮助:)

        <div class="productShippingInformation">
          
          {% if product.tags contains 'Discount Enabled' and current_variant.inventory_policy == 'continue' %}
          
         {% elsif current_variant.inventory_quantity >= 1 %}
           Delivered in 4-6 days.
         {% endif %}
         {% if current_variant.inventory_quantity <= 0 and product.tags contains 'Discount Enabled'%}
          <b>Delivered in 10-14 days.</b>
             {% endif %}
          </div>
        <div class="productShippingInformation">       

          {% if product.tags contains 'Perfume & Aftershave' and current_variant.inventory_policy == 'continue' %}

    {% if current_variant.inventory_quantity <= 0 %}
      <div><b>Delivery in 2021.</b> please allow 20-30 days for delivery</div>
 
    {% elsif current_variant.inventory_quantity >= 1 %}
      <div>Order now for delivery within 7 days</div>

    {% endif %}



{% endif %}
        
         </div>
Questioner
Anthony
Viewed
0
koosa 2020-12-16 12:22:41

我会这样处理:

{% if product.tags contains 'perfume' and current_variant.inventory_policy == 'continue' %}

    {% if current_variant.inventory_quantity <= 0 %}
      <div>Out of Stock please allow 20-30 days for delivery</div>
 
    {% elsif current_variant.inventory_quantity >= 1 %}
      <div>Order now for delivery within 7 days</div>

    {% endif %}

{% else %}
  <div>We have {{ current_variant.inventory_quantity }} in stock for delivery in 4-6 days.</div>

{% endif %}

看来你的主要问题是current_variant.inventory_quantity <= 1什么时候应该current_variant.inventory_quantity >= 1