Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save fida02/fee30ce31b3b85086581445e32c53716 to your computer and use it in GitHub Desktop.

Select an option

Save fida02/fee30ce31b3b85086581445e32c53716 to your computer and use it in GitHub Desktop.
This will disable today date selection of Forminator Datepicker after 8 am
<?php
/**
* Plugin Name: [Forminator] - Disable today on datepicker after specific time
* Plugin URI: https://wpmudev.com/project/forminator-pro/
* Description: Disable today date selection on the Forminator Datepicker after 8 am.
* Author: Fida Al Hasan @ WPMUDEV
* Author URI: https://wpmudev.com/
* License: GPLv2 or later
*/
add_filter( 'forminator_field_date_markup', 'wpmu_fd_disable_date_today_after_time', 11, 2 );
function wpmu_fd_disable_date_today_after_time( $html, $field ) {
$fields = array( 'date-1', 'date-2' ); // comma separated list of datepicker fields
if ( !in_array( $field['element_id'], $fields ) ) {
return $html;
}
$time_limit = strtotime( '08:00:00 ' );
$current_timestamp = current_time( 'timestamp' ); // WordPress time
if ( $current_timestamp >= $time_limit ) {
$tomorrow = new DateTime('tomorrow');
$new_startdate = 'data-start-date="'.$tomorrow->format('Y-m-d').'"';
$today = new DateTime('today');
$old_startdate = 'data-start-date="'.$today->format('Y-m-d').'"';
$html = str_replace( 'data-past-dates="enable"', 'data-past-dates="disable"', $html );
$html = str_replace ( $old_startdate, $new_startdate, $html );
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment