【问题标题】:Remove variants from variants array on product in Liquid从 Liquid 中产品的变体数组中删除变体
【发布时间】:2014-03-02 04:25:38
【问题描述】:

晚上好!我正在尝试使用纯 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 %}

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    我很确定您将需要使用一些 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');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-16
      • 2021-01-26
      • 2023-03-11
      • 2023-03-14
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      相关资源
      最近更新 更多