我正在建立一个使用Shopify的网上商店。我的生意是一家食品生产公司。我进入商业厨房的时间限制在每周一天(星期日),所以我打算在星期一到星期六收集订单,周日做饭,然后再取货。我已经有了很多需要加载到Shopify主题中的代码。首先,我在这个链接https://shopify.dev/tutorials/customize-theme-add-date-picker-for-delivery-dates上使用了自定义代码
但是我需要进一步的定制..。
我需要帮助自定义日期选择可用的日期,根据每周的一天,订单被下。
规则如下:
例子:
周一5/10 -最早的拾件星期一5/17 5/17
<代码>H 124星期日不拾取<代码>H 225<代码>F 226
发布于 2021-05-11 16:27:13
您可以尝试使用datepicker的beforeShowDay
函数来限制可用的天数,如下所示:
window.onload = function() {
if (window.jQuery) {
let $ = window.jQuery;
let today = new Date();
let next_week = today.getTime() + 7 * 24 * 60 * 60 * 1000;
$(function() {
$("#date").datepicker({
beforeShowDay: function(date) {
var day_of_week = date.getDay();
//disable all dates in the past, disable all days of the week after today's day of the week but within 7 days
if (date.getTime() <= today.getTime() || (day_of_week > today.getDay() && date.getTime() < next_week)) {
return [false, ""];
}
//disable all sundays
return [(day_of_week != 0), ""];
}
});
});
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<link href="//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" media="all">
<div style="width:300px; clear:both;">
<p>
<label for="date">Pick a delivery date:</label>
<input id="date" type="text" name="attributes[date]" value="{{ cart.attributes.date }}" />
<span style="display:block" class="instructions"> We do not deliver on Sundays.</span>
</p>
</div>
https://stackoverflow.com/questions/67448702
复制相似问题