【发布时间】:2018-07-03 03:48:05
【问题描述】:
我已将 DatePicker 添加到我的结帐页面,以便客户选择交货日期。还添加了一个脚本来禁用过去的日期(显然)和某些假期的交付。
这是脚本:
<script>
var disableddates = ["14-02-2018", "25-12-2018"];
function DisableSpecificDates(date) {
var string = jQuery.datepicker.formatDate("dd-mm-yy", date);
return [disableddates.indexOf(string) == -1];
}
jQuery(function() {
jQuery("#billing_delivery_date").datepicker({
dateFormat: "DD, d MM, yy",
beforeShowDay: DisableSpecificDates,
minDate: new Date()
});
});
</script>
在我尝试对其施加一些限制之前,它可以完美运行。我只需要禁用某些类别的假日递送,而不是全部。我是这样做的:
function add_checkout_script() {
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// if a product is not in our cat, bail out since we know the cat is not alone
if ( has_term( my_category, 'product_cat', $cart_item['data']->id ) ) {
wp_enqueue_script( 'newscript', get_stylesheet_directory_uri() . '/restrict_day_script.js', array( 'jquery' ));
}
}
}
add_action( 'woocommerce_after_checkout_form', 'add_checkout_script' );
也试过只是粘贴脚本:
function add_checkout_script() {
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// if a product is not in our cat, bail out since we know the cat is not alone
if ( has_term( my_category, 'product_cat', $cart_item['data']->id ) ) {
?>
<script>
var disableddates = ["14-02-2018", "25-12-2018"];
function DisableSpecificDates(date) {
var string = jQuery.datepicker.formatDate("dd-mm-yy", date);
return [disableddates.indexOf(string) == -1];
}
jQuery(function() {
jQuery("#billing_delivery_date").datepicker({
dateFormat: "DD, d MM, yy",
beforeShowDay: DisableSpecificDates,
minDate: new Date()
});
});
</script>
<?php
}
}
}
add_action( 'woocommerce_after_checkout_form', 'add_checkout_script' );
我做错了什么?
【问题讨论】:
标签: php woocommerce cart categories checkout