1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Disable weekends in the date field
  1. Home
  2. Knowledge Base
  3. Date fields
  4. Disable weekends in the date field

Disable weekends in the date field

You can disable weekends in the date field by using this snippet:

<?php
/**
* Set the minimum acceptable date to 10 days in the future
*/
function prefix_date_field_params_disable_weekends( $params, $item ) {
$params[] = "beforeShowDay: $.datepicker.noWeekends";
return $params;
}
add_filter( 'pewc_filter_date_field_params', 'prefix_date_field_params_disable_weekends', 10, 2 );

Disable weekends and holidays

The following snippet will disable weekends and a list of holidays. You need to set the list using the format yy-mm-dd.

<?php
/**
* Disable weekends and holidays
*/
function prefix_date_field_params_disable_weekends_holidays( $params, $item ) {
$params[] = 'beforeShowDay : function( date ) {
// Disable holidays
var holidays = ["2020-04-13","2020-04-14"];
var datestring = jQuery.datepicker.formatDate( "yy-mm-dd", date );
console.log( datestring );
console.log( holidays.indexOf(datestring) );
if( holidays.indexOf( datestring ) != -1 ) {
return [ false, false ];
}
// Disable weekends
var day = date.getDay();
if( day == 0 || day == 6 ) {
return [ false, false ];
}
return [ true ];
}';
return $params;
}
add_filter( 'pewc_filter_date_field_params', 'prefix_date_field_params_disable_weekends_holidays', 10, 2 );

Here’s how to add the snippet to your site.

Was this article helpful?

Need More Support?

If you can't find the answer that you're looking for, then please use the link below to raise a support ticket.
Contact Support

Related Articles