I need to block out a delivery date on my shipping calendar, if a certain product is selected. E.g if we can’t ship sunflowers on the 10th Dec for some reason and the customer has added sunflowers to the cart, when they get to the checkout page, the 10th Dec should be blocked out as unavailable.
I’ve found the following code, but I don’t know how to change it from product categories to single product ids.. and also to be able to specific the date I want blocked. Can anyone help with this please
add_action( 'woocommerce_after_checkout_form', 'add_checkout_script' );
function add_checkout_script() {
// HERE define your product categories in the array (Ids, slugs or names)
$categories = array( 't-shirts', 'sweet-shirts' );
$product_id = $cart_item['product_id'];
$found = false;
// Loop through cart items to find out specific product categories
foreach( WC()->cart->get_cart() as $cart_item )
if( has_term( $categories, 'product_cat', $product_id ) ) {
$found = true;
break;
}
// If product categories are not found in cart items, we exit
if ( ! $found ) return
?>
<script>
jQuery(function($) {
var disableddates = ["14-02-2018", "25-12-2018"];
function DisableSpecificDates(date) {
var string = $.datepicker.formatDate("dd-mm-yy", date);
return [disableddates.indexOf(string) == -1];
}
$("#billing_delivery_date").datepicker({
dateFormat: "DD, d MM, yy",
beforeShowDay: DisableSpecificDates,
minDate: new Date()
});
});
</script>
<?php
}
Thanks!