0
votes

Good evening! I am trying to remove variants from the variant array on a product using pure Liquid(Shopify templating language). I would only like to use javascript as a last resort.

Below is where I am so far. Anything that is the variant in the if check needs to be removed from 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

1 Answers

0
votes

I'm pretty sure you're going to need to use some javascript to achieve this. Take a look at this article on the Shopify wiki: How do I remove sold out variants from my options drop-downs.

Modifying the code in that article for your situation, you'll want something like this:

{% 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');