Shopify themes, liquid, logos, and UX
Hello,
I have a code for Estimate delivery date for my product pages. Using custom CSS section and using the metafields. Works great.
However, I'm wanting to add range date and location from where the customer are from for better estimation dates, USA has different shipping times than Canada.
How can I add range date and location detection? Thanks
CODE:
<style> .delivery-date, .delivery-date p, .delivery-date div { display:inline;} </style> {% if product.metafields.custom.number_of_days_for_delivery != blank %} <div class="delivery-date"> <p><b>Estimated Delivery Date:</b></p> <div id="m-date"> {% assign days_to_add = product.metafields.custom.number_of_days_for_delivery | date: "%s" | times: 86400 %} {% assign future_date = 'now' | date: "%s" | plus: days_to_add | date: "%d %b" %} {{ future_date }} </div> </div> {% endif %}
Solved! Go to the solution
This is an accepted solution.
Hello @xnyjyh , To display the range date create another meta field "Range Date For Delivery" and replace your code with the below code. Also, Replace the meta field code for "product.metafields.custom.range_date_for_delivery" with your meta field.
{% if product.metafields.custom.number_of_days_for_delivery_ != blank %}
<div class="delivery-date">
<p><b>Estimated Delivery Date:</b></p>
<div id="m-date">
{% if product.metafields.custom.range_date_for_delivery != blank %}
{% assign range_date_add = product.metafields.custom.range_date_for_delivery | date: "%s" | times: 86400 %}
{% assign range_date = 'now' | date: "%s" | plus: range_date_add | date: "%d %b" %}
{% endif %}
{% assign days_to_add = product.metafields.custom.number_of_days_for_delivery_ | date: "%s" | times: 86400 %}
{% assign future_date = 'now' | date: "%s" | plus: days_to_add | date: "%d %b" %}
{% if range_date %} {{ range_date | append: ' to ' }} {% endif %} {{ future_date }}
</div>
</div>
{% endif %}
This is an accepted solution.
Hello @xnyjyh , To display the range date create another meta field "Range Date For Delivery" and replace your code with the below code. Also, Replace the meta field code for "product.metafields.custom.range_date_for_delivery" with your meta field.
{% if product.metafields.custom.number_of_days_for_delivery_ != blank %}
<div class="delivery-date">
<p><b>Estimated Delivery Date:</b></p>
<div id="m-date">
{% if product.metafields.custom.range_date_for_delivery != blank %}
{% assign range_date_add = product.metafields.custom.range_date_for_delivery | date: "%s" | times: 86400 %}
{% assign range_date = 'now' | date: "%s" | plus: range_date_add | date: "%d %b" %}
{% endif %}
{% assign days_to_add = product.metafields.custom.number_of_days_for_delivery_ | date: "%s" | times: 86400 %}
{% assign future_date = 'now' | date: "%s" | plus: days_to_add | date: "%d %b" %}
{% if range_date %} {{ range_date | append: ' to ' }} {% endif %} {{ future_date }}
</div>
</div>
{% endif %}
this is the current metafield i had. on the product page I get only one option to input a number. with this new code, how would I set up the metafield and what would I input in the product metafield option?
UPDATE::: you had underscores at the end of the metafield coding. Once removed, it works great. Thanks!
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024