Delivery Date picker

Delivery Date picker

BIAB
Not applicable
2 0 0

Hello,

 

Im trying to implement the default delivery date picker  snippet.

 

https://help.shopify.com/en/manual/online-store/themes/customizing-themes/add-date-picker

 

But I would like to adjust it by excluding some days based on the day and hour of the order /

 

- If current time is later then 1pm from Monday to Friday , exclude next day

- If it is Saturday before 1 pm , exclude next day

- If it is Saturday after 1 pm , exclude next 2 days

- if it is Sunday , exclude next day

- Exclude all Sundays.

 

All help or tips are appreciated , Thanks

 

I have this code now but it is failing :

 

{{ '//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css' | stylesheet_tag }}

<div style="width:300px; clear:both;">
<p>
<label for="date">Kies je leverdatum:</label>
<input id="date" type="text" name="attributes[date]" value="{{ cart.attributes.date }}" />
<span style="display:block" class="instructions"> We leveren niet op zondag.</span>
</p>
</div>

<script>
window.onload = function() {
if (window.jQuery) {
let $ = window.jQuery;

$(function() {
$("#date").datepicker({
minDate: 0, // Disables past dates
beforeShowDay: function(date) {
var day = date.getDay();
// Disable Sunday selection
if (day == 0) {
return [false];
} else {
return [true];
}
}
});

// Check the current day and time to determine selectable dates
var currentDay = new Date().getDay();
var currentTime = new Date().getHours();

// If it's Sunday, disable the next day (Monday)
if (currentDay == 0) {
$("#datepicker").datepicker("option", "minDate", 1);
}
// If it's Saturday after 1 PM, disable the next two days (Sunday and Monday)
else if (currentDay == 6 && currentTime >= 13) {
$("#datepicker").datepicker("option", "minDate", 2);
}
// For Monday to Friday, if the current time is after 1 PM, disable the next day
else if (currentDay >= 1 && currentDay <= 5 && currentTime >= 13) {
$("#datepicker").datepicker("option", "minDate", 1);
}
});
}
 
 
 
}
</script>

 

 

Reply 1 (1)
BIAB
Not applicable
2 0 0

Thanks for your help.

I tried the code but still have the same issue .

It is sunday 11h14 pm now and I get this :

BIAB_0-1725830125649.png

Delivery on Monday the 9th should not be possible.