Filtering variants by date

Solved
Excursionist
13 1 3

I am trying to do something that should be relatively simple.  I have a product with a variant option.  I've added three variants and set a date for each of the variants in this option.  Im trying to loop through the variants and only display those where the date is in the FUTURE.  For some reason, only the last option appears to have the date filter applied.

 

 {% for variant in product.variants %}
      {% assign today_date = 'now' | date: '%s' %}
      {% assign v_date = variant.option1 |  date: "%s"  %}
      {% if v_date >= today_date %}
        <li>** {{ v_date }} >? {{ today_date }} - {{ variant.option1 }}</li>
      {% else %}
        <li>{{ v_date }} >? {{ today_date }} - {{ variant.option1 }}</li>
      {% endif %}
    {% endfor %}

results in this output:

 

 

  • 10/21/2019 >? 1569283699 - 10/21/2019
  • 10/28/2019 >? 1569283699 - 10/28/2019
  • 1554966000 >? 1569283699 - 11/04/2019

Any thoughts?  Ideally, I would like to loop through all the variants for my product, create a new array of just these variants, and then deal with them, but not sure if I can do that either.  Right now, I can't even get the date filtering to work.

 

 

0 Likes
Shopify Partner
1125 90 137

Hi @fruitstand_josh ,

 

Can you share your store URL, So i can assist you better!

 

 

Thanks & Regards
Perennial Solution

Problem Solved?✔️Like and Accept the solution that can help others.
Need any help with theme customization or design? Hire us
Email: infoperennialsolution@gmail.com
Skype: infoperennialsolution
0 Likes

Success.

Excursionist
13 1 3

Thanks Perennial.

 

I was able to make this work by changing how I entered dates from 10/21/2019 to Oct 21, 2019.  Weird that it wouldn't properly parse all the dates but that did work.


Best,

 

Josh

0 Likes