从液体中产品的变体数组中移除变体 [英] Remove variants from variants array on product in Liquid

查看:13
本文介绍了从液体中产品的变体数组中移除变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好!我正在尝试使用纯液体(Shopify模板语言)从产品的Variant数组中删除Variant。我只想在不得已的情况下使用Java脚本。

下面是我目前所在的位置。需要从currentProduct.variants中删除IF检查中的任何变体。

{% 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 %}

推荐答案

我非常确定您将需要使用一些Java脚本来实现这一点。请查看Shopify维基上的这篇文章: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');

这篇关于从液体中产品的变体数组中移除变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆