Shopify Flow - tagging orders that meet mail cut-off time

Hi,

We have a requirement to tag orders that meet the mail-cut-off time. This was easily achieved in the previous app that we used (Order Tagger). With Flow, it seems the process is a little restricted when it comes to dynamic values. I.e, when comparing dates, there’s no way to compare against a set time etc.

The way we thought we could do it was doing something like this…

When order created —> Assign new tag with the value of:

{% assign order_time = order.createdAt | date: "%s" %}
{% assign cutoff_time = order.createdAt | date: "%Y-%m-%d 10:00" | date: "%s" %}
{% assign weekday = order.createdAt | date: "%u" %}
{% if order_time > cutoff_time and weekday < 6 %}after-cutoff{% else %}same-day-dispatch{% endif %}

This logic checks out in my liquid sandbox, but with Flow, the value always resolves to ‘same-day-dispatch’ when an order is placed before 3 pm and when it’s placed after, it seems to error instead. I’m a little confused.

Thanks,

Drew

Flow does not support all Liquid but a subset. It does not support assign and capture yet. I don’t think you can yet do this in Flow.

Thanks for your response. Ah, that’s a shame. Also a shame that it isn’t made clear in the documentation and I spent an entire evening trying to make it work. With that said, is there any other option that I could try? More outside of the box kind of ideas as time or date comparisons don’t seem to be supported (at least in a way that is useful).

Where there’s a will, there’s a way! At least I believe I’ve found a solution that doesn’t use logical statements but instead uses a clever sequence of math and string filters.

Basically we just convert the order date/time to a integer and then subtract the cut-off time from that value using the same unit of measurement (i.e, subtract the hour+1 from the hour, or if you need minute precision, times the hours by 60 and add the additional minutes+1 and subtract against the same). We can then use the zero point as the logical switch. If it’s a minus, then we know there’s still time left and if it’s a plus, we know the cut-off time is larger and we’ve gone less than 0. Once we have that understanding, we can normalise to 0 or 1 and then swap those out for actual string values with a replace filter to use in our tags directly.

Hope this helps someone. Actually, if someone has any other clever ways to shorten this, I would be very interested.

{{ order.createdAt | date: "%H" | minus: 14 | at_most: 1 | at_least: 0 | replace: '0', 'same-day-dispatch' | replace: '1', 'after-cutoff-order' }}