Hi @ewhitenack,
Please try this snippet as a workaround and see whether that helps:
<?php
add_action( 'forminator_form_after_save_entry', 'wpmudev_disable_dates_calendar', 10, 2 );
add_action( 'forminator_form_after_handle_submit', 'wpmudev_disable_dates_calendar', 10, 2 );
function wpmudev_disable_dates_calendar( $module_id, $response ) {
if ( $module_id != 2910 ) {
return;
}
if ( $response && is_array( $response ) ) {
if ( $response['success'] ) {
$form_meta = get_post_meta( $module_id, 'forminator_form_meta', true );
if ( $form_meta ) {
$update_meta = false;
if ( isset( $form_meta['fields'] ) ) {
foreach ( $form_meta['fields'] as $form_key => $form_val ) {
if ( $form_val['id'] == 'date-1' ) {
if ( isset( $_POST ) ) {
$date = isset( $_POST['date-1'] ) ? sanitize_text_field( $_POST['date-1'] ) : '';
$date_submit = wpmudev_get_date_entries( $module_id, $date );
if ( $date_submit ) {
$form_meta['fields'][$form_key]['disabled-dates'][] = $date;
$update_meta = true;
}
}
}
}
}
if ( $update_meta ) {
update_post_meta( $module_id, 'forminator_form_meta', $form_meta );
}
}
}
}
}
function wpmudev_get_date_entries( $form_id, $date_val ) {
global $wpdb;
$table_name = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY_META );
$entry_table_name = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY );
$sql = "SELECT m.
entry_id
FROM {$table_name} m LEFT JOIN {$entry_table_name} e ON(e.entry_id
= m.entry_id
) WHERE e.form_id
= %d AND m.meta_key
= %s AND m.meta_value
= %s order by m.meta_id
";
$entry_ids = $wpdb->get_results( $wpdb->prepare( $sql, $form_id, 'date-1', $date_val ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
if ( ! empty( $entry_ids ) && count( $entry_ids ) >= 4 ) {
return true;
}
return false;
}
You’ll need to update the line in the above code with your form ID ie:
if ( $module_id != 2910 ) {
Suppose the form ID is 123 the above line will change as follows:
if ( $module_id != 123 ) {
At the moment, the snippet will only allow the date to be entered 4 times based on the following line:
if ( ! empty( $entry_ids ) && count( $entry_ids ) >= 4 ) {
If you want to change that to 2 times etc then you can update the value of 4 to 2 ie as follows:
if ( ! empty( $entry_ids ) && count( $entry_ids ) >= 2 ) {
I gave a quick test and confirm the snippet works fine. The snippet can be added 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
Please do let us know how that goes.
Best Regards,
Nithin