【发布时间】:2020-03-02 15:38:39
【问题描述】:
{% for orders in checkout.customer.orders %}
//count the orders
{% endfor %}
我需要计算特定日期之后的订单吗? 如何在 Liquid / Shopify 中执行此操作?
【问题讨论】:
-
你能告诉我们你到目前为止做了什么吗?
标签: shopify liquid shopify-template
{% for orders in checkout.customer.orders %}
//count the orders
{% endfor %}
我需要计算特定日期之后的订单吗? 如何在 Liquid / Shopify 中执行此操作?
【问题讨论】:
标签: shopify liquid shopify-template
所有订单都有一个created_at 日期,您可以使用Liquid date filter 以各种格式输出 - 您可以通过上述订单循环,并使用 unix 格式将其与所讨论的“阈值日期”进行比较比较日期:
{% 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 %}
然后您可以输出{{ ordersCount }}。
注意:我不认为 Shopify 将允许您分页超过 50 个订单。
【讨论】: