1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Set minimum date into the future
  1. Home
  2. Knowledge Base
  3. Date fields
  4. Set minimum date into the future
  1. Home
  2. Knowledge Base
  3. Front End
  4. Set minimum date into the future
  1. Home
  2. Knowledge Base
  3. Advanced
  4. Set minimum date into the future

Set minimum date into the future

You can filter the date field’s minimum date setting so that it is a certain number of days into the future. In this example, we are setting the minimum date 10 days ahead – so if today is February 17, the first selectable date in the field will be February 27.

Change the ’10’ to ‘1’ if you want the minimum date to be tomorrow.

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

Here’s how to add a snippet.

Set minimum date based on current time

Maybe you want to set the minimum date two days into the future if the current time has passed a certain point. In the example below, the minimum date is tomorrow, unless the current time is later than 6pm.

<?php
/**
* Set the minimum date differently if we're currently later than 18:00
*/
function prefix_date_field_params_after_time( $params, $item ) {
// Check if the time is later than 18:00
if( date( 'H' ) >= 18 ) {
$min_date = 2;
} else {
$min_date = 1;
}
$params[] = '"minDate" : ' . $min_date;
// $params[] = "beforeShowDay: $.datepicker.noWeekends";
return $params;
}
add_filter( 'pewc_filter_date_field_params', 'prefix_date_field_params_after_time', 10, 2 );

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