简体   繁体   中英

How can filter orders made after a certain date in liquid/ Shopify?

{% for orders in checkout.customer.orders %}
//count the orders 
{% endfor %}

I need to count orders made only after a certain date? How can I do this in Liquid / Shopify?

All Orders have a created_at date that you can output in various formats using the Liquid date filter — you would loop thru the Orders as above and compare that with whatever the "threshold date" in question is, using unix-format dates for comparison:

{% assign ordersThresholdUnix = '2019-01-01' | date: '%s' %}
{% assign ordersCount = 0 %}
{% for orders in checkout.customer.orders %}
  {% assign orderDateUnix =  order.created_at | date: '%s' %}
  {% if orderDateUnix > ordersThresholdUnix %}
    {% assign ordersCount = 0 %}
  {% endif %}
{% endfor %}

You can then output {{ ordersCount }} .

Note: that I don't think Shopify will allow you to paginate further back than 50 Orders.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM