从Liquid中的产品中删除变体数组中的变体

时间:2014-03-02 04:25:39

标签: shopify liquid

晚上好!我试图使用纯Liquid(Shopify模板语言)从产品中的变体数组中删除变体。我只想用javascript作为最后的手段。

以下是我到目前为止的地方。 if检查中的任何变体都需要从currentProduct.variants中删除。

{% assign currentProduct = product %}
   {% for variant in currentProduct.variants %}
     {% include 'shappify-variant-is-csp' %}
     {% if csp_variant != 1 %}
        //need to remove the object that meets this if statement
     {% endif %}
{% endfor %}

1 个答案:

答案 0 :(得分:0)

我很确定你需要使用一些javascript来实现这一目标。在Shopify wiki上查看这篇文章:How do I remove sold out variants from my options drop-downs

根据您的情况修改该文章中的代码,您需要这样的内容:

{% for variant in product.variants %}
   {% include 'shappify-variant-is-csp' %}
   {% if csp_variant != 1 %}
      jQuery('.single-option-selector option').filter(function() { return jQuery(this).html() === {{ variant.title | json }}; }).remove();
   {% endif %}
{% endfor %}
jQuery('.single-option-selector').trigger('change');
相关问题