Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wp_footer', function () {
- if ( ! is_page('contact') ) return; // change 'contact' to your page slug or page ID
- ?>
- <script>
- (function($){
- //Dates to disable (ISO format: YYYY-MM-DD)
- const DISABLED_DATES = ["2025-09-10","2025-09-15","2025-12-25"];
- function applyDisable($scope){
- const $inputs = ($scope && $scope.find)
- ? $scope.find('.elementor-field-type-date input')
- : $('.elementor-field-type-date input');
- $inputs.each(function(){
- const input = this;
- (function waitForFP(tries){
- const fp = input._flatpickr;
- if (fp) {
- const existing = Array.isArray(fp.config.disable) ? fp.config.disable : [];
- fp.set('disable', existing.concat(DISABLED_DATES));
- fp.set('onClose', [
- function(selectedDates, dateStr) {
- if (!dateStr) return;
- const isDisabled = (fp.config.disable || []).some(rule => {
- if (typeof rule === 'string') return rule === dateStr;
- if (typeof rule === 'function') {
- return rule(fp.parseDate(dateStr, 'Y-m-d'), '', fp) === false;
- }
- return false;
- });
- if (isDisabled) {
- this.clear();
- this.input.blur();
- alert('That date is unavailable. Please choose another.');
- }
- }
- ]);
- return;
- }
- if (tries <= 0) return;
- setTimeout(function(){ waitForFP(tries - 1); }, 100);
- })(30);
- });
- }
- $(function(){ applyDisable($(document)); });
- if (window.elementorFrontend && elementorFrontend.hooks) {
- elementorFrontend.hooks.addAction('frontend/element_ready/form.default', applyDisable);
- }
- $(document).on('elementor/popup/show', function(){ applyDisable($(document)); });
- })(jQuery);
- </script>
- <?php
- });
Advertisement
Add Comment
Please, Sign In to add comment