【问题标题】:Get Weight Of Product In Shopify Liquid Language在 Shopify Liquid Language 中获取产品重量
【发布时间】:2019-07-12 05:00:20
【问题描述】:

我正在尝试根据为该产品输入的重量来获取该产品的重量。从那里使用 IF 语句来显示运费或免费送货。

这是我目前拥有的代码,但它根本不起作用。

 {% if currentvariant.weight == '99' %}
 FREE WORLDWIDE SHIPPING
 {% endif %}

如果产品的重量输入为 99,则设置为免运费。所以我试图让它显示全球免费送货。

使用的模板是 Debut。 我放置代码的文件是 product-template.liquid

我也尝试为它分配一个变量。例如:

 {% assign the_weight = currentvariant.weight %}

 {% if the_weight == '99' %}
 FREE WORLDWIDE SHIPPING
 {% endif %}

我也尝试过使用 '99.0' 以防万一它将 .0 放入变量中,但它也不起作用。

我也试过variant.weight,但也没有用。

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    尝试在产品模板文件中使用-

    {{ product.variants.first.weight | weight_with_unit }}
    

    【讨论】:

      【解决方案2】:

      我想通了。以防万一有人想要这样做,这是我正在使用的代码。

          {% assign skip = '0' %}
          {% for variant in product.variants %}
          {% assign theweight = variant.weight | weight_with_unit %}
          {% if skip == '0' %}
          {% if theweight == '99.0 lb' %}
          <span style="font-size:18px; color:red;"><b>FREE WORLDWIDE SHIPPING</b></span>
          {% endif %}
          {% assign skip = '1' %}
          {% endif %}
          {% endfor %}
      

      这是基于我将某些产品的重量设置为 99.0 磅并将该重量设置为免费送货这一事实。您需要将 99.0 磅更改为您设置为免费送货的任何重量,如果您没有以磅为单位设置重量,也将其更改为您的体重。示例:99.0 公斤

      Skip 位于其中,因为它会为您对该产品的每个变体显示免费送货,而我们只想显示一次。

      【讨论】:

        猜你喜欢
        • 2023-02-26
        • 2023-02-08
        • 1970-01-01
        • 2012-10-27
        • 1970-01-01
        • 1970-01-01
        • 2020-09-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多