【问题标题】:Get the quantity of the currently selected variant - cart.liquid获取当前选择的变体的数量 - cart.liquid
【发布时间】:2021-09-22 17:53:26
【问题描述】:

我想获取当前所选变体的确切库存数量

我已经尝试过这段代码,但它返回了变量的所有数量。我只需要在购物车中选择的那个

{% endraw %}

{% assign product_qty = 0 %}

{% for variant in product.variants %}

{% if variant.inventory_quantity <= 0 %}
<p>{{variant.inventory_quantity}}</p>
{% assign product_qty = product_qty | plus: variant.inventory_quantity %}

{% endif %}

{% endfor %}

输出:
-3
0
0
0

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    解决方案: 添加如果在:

    {% if variant.selected %}
    <p>{{variant.inventory_quantity}}</p>
    {% endif%}
    

    【讨论】:

    • 请在您的答案中添加一些解释,以便其他人可以从中学习
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多