Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
Hope you guys can help me. I use a custom liquid on all product pages.
{% elsif product.metafields.custom.expected_date != blank %}
<p style="color: #ff9f0f;">Expected on stock date: {{ product.metafields.custom.expected_date | date: '%d-%m-%Y' }}
This works nicely but I want to hide this when the date is in the past.
I have tried the following code but that does not work.
{% assign today_date = 'now' | date: '%s' %}
{% assign pre_date = product.metafields.custom.expected_date | date: '%s' %}
{% elsif product.metafields.custom.expected_date != blank and today_date < pre_date %}
<p style="color: #ff9f0f;">Expected on stock date:: {{ product.metafields.custom.expected_date | date: '%d-%m-%Y' }}</p>
{% endif %}
Any ideas on how to get this working?
Thanks!
Solved! Go to the solution
This is an accepted solution.
Pages are cached on shopify so even if the comparison was working when you check it today the values being compared would never change in many instances of the page being served so in the future the stale values are what's compared.
If can be a bit more reliable using shopify-flow , such as with a schedule trigger , to toggle a metafield for the display; which should trigger a cache update, rather than try to rely on dates being cached.
Alternatively use javascript and check the time with an external time service (don't trust the users browser time/date)
As for finding any issues in liquid code itself, sanity check assumptions and just raw output everything being used:
{% assign today_date = 'now' | date: '%s' %}
today_date : {{ today_date }}<br>
{% assign pre_date = product.metafields.custom.expected_date | date: '%s' %}
pre_date : {{ pre_date }}<br>
{% if today_date < pre_date %}
it's expected
{% else %}
it's arrived
{% endif %}
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
This is an accepted solution.
Pages are cached on shopify so even if the comparison was working when you check it today the values being compared would never change in many instances of the page being served so in the future the stale values are what's compared.
If can be a bit more reliable using shopify-flow , such as with a schedule trigger , to toggle a metafield for the display; which should trigger a cache update, rather than try to rely on dates being cached.
Alternatively use javascript and check the time with an external time service (don't trust the users browser time/date)
As for finding any issues in liquid code itself, sanity check assumptions and just raw output everything being used:
{% assign today_date = 'now' | date: '%s' %}
today_date : {{ today_date }}<br>
{% assign pre_date = product.metafields.custom.expected_date | date: '%s' %}
pre_date : {{ pre_date }}<br>
{% if today_date < pre_date %}
it's expected
{% else %}
it's arrived
{% endif %}
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Notes for inventory date behaviors in shopify-flow,
Good Hunting.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025