Hi @carcayu80,
Could you please try the following snippet and then check whether it helps?
<?php
add_action( 'forminator_before_form_render', 'wpmudev_disable_specific_dates', 10, 5 );
function wpmudev_disable_specific_dates( $id, $form_type, $post_id, $form_fields, $form_settings ){
if( $id != 361 ){
return;
}
$update = false;
$form_meta = get_post_meta($id, 'forminator_form_meta', true);
if( $form_meta ){
if( isset( $form_meta['fields'] ) ){
foreach( $form_meta['fields'] as $form_key => $form_val ){
if( $form_val['id'] == 'date-1' ){
$timestamp = strtotime(date('Y')."-05-00 first friday");
$first_friday = date("m/d/Y", $timestamp);
$second_timestamp = strtotime(date('Y', strtotime('+1 year'))."-01-00 first sunday -14 days");
$second_last_sunday = date("m/d/Y", $second_timestamp);
if( is_array( $form_meta['fields'][$form_key]['disabled-dates'] ) ) {
if( in_array( $first_friday, $form_meta['fields'][$form_key]['disabled-dates'] ) ) {
return;
}
if( in_array( $second_last_sunday, $form_meta['fields'][$form_key]['disabled-dates'] ) ) {
return;
}
}
if( $first_friday ){
$form_meta['fields'][$form_key]['disabled-dates'][] = $first_friday;
$update = true;
}
if( $second_last_sunday ){
$form_meta['fields'][$form_key]['disabled-dates'][] = $second_last_sunday;
$update = true;
}
}
}
}
if( $update ) {
update_post_meta($id, 'forminator_form_meta', $form_meta);
}
}
add_filter( 'forminator_field_date_markup', 'wpmudev_disabled_dates_specified', 10, 3 );
}
function wpmudev_disabled_dates_specified( $html, $field, $cls ) {
if( $field['element_id'] == 'date-1' ){
$disabled_dates = array();
$timestamp = strtotime(date('Y')."-05-00 first friday");
$first_friday = date("m/d/Y", $timestamp);
$second_timestamp = strtotime(date('Y', strtotime('+1 year'))."-01-00 first sunday -14 days");
$second_last_sunday = date("m/d/Y", $second_timestamp);
$disabled_dates[] = $first_friday;
$disabled_dates[] = $second_last_sunday;
$disabled_date = implode( ',', $disabled_dates );
if( strpos( $html, 'data-disable-date=""') !== false ){
$html = str_replace('data-disable-date=""', "data-disable-date=$disabled_date", $html);
}
}
return $html;
}
In the above code you’ll need no update the number 361 in the following line:
if( $id != 361 ){
To your form ID, suppose your form ID is 123, then the above line will change to:
if( $id != 123 ){
You can implement the above code as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
Once the above code is applied, it should update the “Disabled Dates” in the “Datepicker” field.
Kind Regards,
Nithin