简体   繁体   中英

Shopify Liquid : IF < "certain time of day"

Im trying to display a message in Shopify Liquid if the current time of the user is before 16:00 (London Time) or a different message if its past 16:00. On top of this i'd also like a seperate message depending on the day.

My current code looks like this but im not sure how I can now get an If statement into each case.

{% assign day = 'now' | date: '%A' %}
{% assign time = 'now' | date: '%R' %} 

{% case day %}
{% when "Monday" %}
{% when "Tuesday" %}
{% when "Wednesday" %}
{% when "Thursday" %}
{% when "Friday" %}
{% when "Saturday" %}
{% when "Sunday" %}
{% else %}
 Error
{% endcase %}

{{ day }}
{{ time }}
{% endif %}

Okay figured it out after a little research. Instead of using the unix timestamp like i was doing i should have been using the hour format

{% assign time = 'now' | date: '%k' | plus: 0 %} 

You can then simply use an if statement such as:

{% if time < 15 %}
   do something
{% endif %}

Saw a couple of other forums asking how this can be achieved with no answers so hopefully this will help atleast 1 person!

Note: You have to include the | plus: 0 | plus: 0 to convert the time variable to something than can be compared with a numerical value

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