Home / Admin / Disabling Past Times on the Date / Time Field
Duplicate Snippet

Embed Snippet on Your Site

Disabling Past Times on the Date / Time Field

This snippet disables past times on the Time Picker field in WPForms.

<10
Code Preview
php
<?php
/**
 * Disable past times from the time field
 *
 * @link   https://wpforms.com/how-to-disable-past-times-on-the-time-picker/
 */
 
function wpf_dev_cond_time() {
   ?>
   <script type="text/javascript">
 
      // Find out the current time
      var now = new Date();
 
      // Take that current time and round it up so we have an even number on the interval
      now.setHours( now.getHours() + Math.round(now.getMinutes()/90) );
        
      window.wpforms_999_8 = window.wpforms_999_8 || {};
      window.wpforms_999_8.timepicker = {
         forceRoundTime: true,
 
         // Disable any times that have passed already and return the new time selections
         minTime: now.toLocaleTimeString()
      };
 
 
   </script>
   <?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_dev_cond_time', 10 );

Comments

Add a Comment