How can I restrict my datepicker with the date of today? I’m building a reservation form for a hotel and I’m looking for a way to disable all dates in the past.
I know that the flatpickr library has the option “today” but I have no idea how to implement this into my functions.php next to this code:
add_filter( 'bricks/element/form/datepicker_options', function( $options, $element ) {
if ( $element->id === 'odwufj' ) {
// localize the form "odwufj" element
$options['locale'] = 'en';
}
return $options;
}, 10, 2 );
Hey Ioannis,
the following snippet should work:
add_filter( 'bricks/element/form/datepicker_options', function( $options, $element ) {
if ( $element->id === 'zownzf' ) {
$options['minDate'] = wp_date( $options['dateFormat'] );
}
return $options;
}, 10, 2 );
Replace the zownzf
in my snippet with your form element’s ID.

See Form Element – Bricks Academy.
Let me know if that helped.
Best,
André
Hey André,
it didn’t work with your code, but thank you for the tip how to implement the minDate inside $options. I just add another line with $options[minDate] = ‘today’;.
This worked for me. I hope it is the correct way.
/** Customize datepicker **/
add_filter( 'bricks/element/form/datepicker_options', function( $options, $element ) {
$options['locale'] = [
'firstDayOfWeek' => 1 // Set Monday as the first week day
];
$options['minDate'] = 'today'; // Disable all past dates
return $options;
}, 10, 2 );
Best from Hamburg
Ioannis
Hey Ioannis,
that’s strange. Worked for me. But according to the flatpickr documentation ‘today’ should be fine as well. Glad I could help.
Best,
André
1 Like