Liquid, JavaScript, themes, sales channels
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 %}
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
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 %}
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
Notes for inventory date behaviors in shopify-flow,
Good Hunting.
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
User | RANK |
---|---|
37 | |
27 | |
14 | |
13 | |
9 |
Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023