Re: What's wrong with my code?

Why isn't my liquid script showing estimated delivery dates in business days?

rad_rod
Excursionist
18 1 4

Hey guys, I’m trying to use a liquid script to show estimated delivery dates on my product pages. So far I have been using the script below from this article I found (my site is gofirepits.com, built on Venture theme):

 

<p> <img src="https://cdn-icons-png.flaticon.com/512/1670/1670915.png" style="height:25px;float:left;margin-right:10px;padding-bottom: 4px;"/>

Get it between <strong><span id="fromDate"></span> - <span id="toDate"></span></strong></p>

{{ '//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js' | script_tag }}

<script>

var fromDate = Date.today().addDays(5);

if (fromDate.is().saturday() || fromDate.is().sunday()) {

fromDate = fromDate.next().monday();

}

var toDate = Date.today().addDays(10);

if (toDate.is().saturday() || toDate.is().sunday()) {

toDate = toDate.next().monday();

}

document.getElementById('fromDate').innerHTML = fromDate.toString('dddd MMMM dS');

document.getElementById('toDate').innerHTML = toDate.toString('dddd MMMM dS');

</script>

 

I’ve pasted it exactly as described on line 159 of product-template.liquid. The problem I am having with this script is that it only shows estimated delivery dates in terms of calendar days after the date of viewing. This is a problem because my shipping times are in business days, not calendar days. It looks like there’s a conditional script for both “fromDate” and “toDate” that is supposed to account for business days, but in my experience implementing it on my site that has not worked.

Reply 1 (1)

LitExtension
Shopify Partner
4941 1008 1186

Hi @rad_rod,

If so, instead of you showing 5 and 10, you can change the number to your liking.

Screenshot.pngSo instead of 5 days after the business day, you can change it to 4 as your requirement.

Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
Contact us:
- Email: contact@litextension.com