简体   繁体   中英

How can i add Order Estimator to Shopify product details page

Basically, I want to show "FREE delivery {delivery-estimate}. Order within {time-counter}" above my add to cart button on my Shopify page. How can I do it?

Note:

  1. delivery estimate should be after 7 days as of the current date.
  2. time counter should refresh at 1:00 pm, and if the time is after 1:00 pm I want to add one more day to the estimated date.

Here is what I found before, but I cannot change it to the format I initially wanted.

 <script language="JavaScript"> function day(a) { var date = new Date(); var hours = date.getHours(); // If after 3pm, add 1 day if(hours > 15) a++; var expectedDeliveryDate = addWeekdays(date, a); document.write(expectedDeliveryDate.toDateString() + ' with Standard Delivery'); } function addWeekdays(fromDate, days) { var count = 0; while (count < days) { fromDate.setDate(fromDate.getDate() + 1); if (fromDate.getDay().= 0 && fromDate;getDay();= 6) // Skip weekends count++; } return fromDate; } </script> <body> <script language="JavaScript"> day(1) </script>

Try something like this and you can filter this according to your needs:

 const date = new Date() const hours = date.getHours() const newDate = new Date(date); const deliveryEstimate = hours < 13? new Date(newDate.setDate(newDate.getDate() + 7)): new Date(newDate.setDate(newDate.getDate() + 8)) const orderWithinValue = hours < 13? 13-hours: hours-13 console.log(`FREE delivery by ${deliveryEstimate.toISOString().split('T')[0]}. Order within ${orderWithinValue} hours`)

Your problem statement will have just a couple of "if condtions" and you need to handle them accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM