Show content based on order date

sunchard
New Member
4 0 0

Hello, 

My store does local delivery. I need to modify the order status and order confirmation page based on the day of the week of the order date. If the customer orders on Friday or Saturday, then the delivery is Monday. If not, the delivery will be tomorrow. 

I started to use this code, but I'm not sure if the capture date will reference today's date or the order date. Can you please me help me figure out the correct code to use.

{% capture day %}{{ 'now' | date: '%A' }}{% endcapture %}{% case day %}  {% when 'Sunday' %}tomorrow  {% when 'Monday' %}  tomorrow  {% when 'Tuesday' %}tomorrow  {% when 'Wednesday' %} tomorrow  {% when 'Thursday' %}tomorrow  {% when 'Friday' %}Monday  {% when 'Saturday' %} Monday{% endcase %} 

Replies 3 (3)

PaulNewton
Shopify Partner
6274 573 1319

I'm not sure if the capture date will reference today's date or the order date

While it should be at the time that "now" when it's rendered unfortunately I think it's ambiguous because of cache'ing either on the users end or shopifys servers.

So if you did it thursday "now" would output tomorrow and you then again visited friday but it's cached from thursday it would say tomorrow.

Really you'd want to support this with frontend javascript checking either a clock api ,  or the users system time(keeping in mind users system time is also unreliable)

 

{%- capture day -%}
    {{- 'now' | date: '%A' -}}
    {%- endcapture -%}
{%- case day -%}  
    {%- when 'Sunday' -%}tomorrow
    {%- when 'Monday' -%}tomorrow
    {%- when 'Tuesday' -%}tomorrow
    {%- when 'Wednesday' -%}tomorrow
    {%- when 'Thursday' -%}tomorrow
    {%- when 'Friday' -%}Monday
    {%- when 'Saturday' -%}Monday
{%- endcase -%} 

 

Alt

{%- capture day -%}
    {{- 'now' | date: '%A' -}}
{%- endcapture -%}
{%- case day -%}  
    {%- when 'Friday' -%}Monday
    {%- when 'Saturday' -%}Monday
    {%- else -%}tomorrow
{%- endcase -%}

 

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


sunchard
New Member
4 0 0

Thanks Paul! I appreciate the quick response! Thanks for the simplified version of the code.

"So if you did it thursday "now" would output tomorrow and you then again visited friday but it's cached from thursday it would say tomorrow." Does this mean the caching will work in my favor to retain tomorrow or Monday depending on the day the customer ordered?

If not, is there a way to reference the day of the order created on date instead of 'now'? 

sunchard
New Member
4 0 0

I use your alternate code provided, but I checked the order confirmation email preview and the words are jumbled together. See screenshot below. 

Screen Shot 2021-11-12 at 7.18.31 AM.png

Can you adjust the code? Forgive me, but I don't have any experience with coding.