wpgenie

limit datepicker so past dates cannot be selected

Jul 31st, 2023
1,922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. /*
  2. wpgenie.org
  3.  
  4. limit date picker so past dates cannot be selected, this JS code snippet should go to your child theme functions.php or customization plugin
  5. https://wpgenie.org/tutorials-category/code-snippets-and-template-customizations-using-child-theme
  6.  
  7. */
  8.  
  9. function wpgenie_limit_past_dates_in_datepicker() {
  10.     ?>
  11.     <script>
  12.     jQuery(document).ready(function($) {
  13.         jQuery('.datetimepicker').datetimepicker(
  14.             {defaultDate: "",
  15.             dateFormat: "yy-mm-dd",
  16.             numberOfMonths: 1,
  17.             showButtonPanel: true,
  18.             minDate: new Date(),
  19.             showOn: "button",
  20.             buttonImage: SA_Ajax.calendar_image,
  21.             buttonImageOnly: true
  22.             });
  23.     });
  24.     </script>
  25.     <?php
  26. }
  27. add_action( 'admin_head', 'wpgenie_limit_past_dates_in_datepicker' );   // loads JS in wp-admin / backend, comment line if not required in backend
  28. add_action( 'wp_head', 'wpgenie_limit_past_dates_in_datepicker');       // loads JS in frontend, comment line if not required in frontend
Advertisement
Add Comment
Please, Sign In to add comment