Last active
July 4, 2024 04:16
-
-
Save JuliaKiselyova/11d73ea7a27108655ace6a913140a7bc to your computer and use it in GitHub Desktop.
Block date after booked days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function handleBlockedDates(config, daysToBlock) { | |
| const validateDay = config.beforeShowDay; | |
| config.beforeShowDay = function (t) { | |
| const day = moment(t); | |
| const value = jQuery("[data-field-name='_capacity']:checked").val(); | |
| if (value == 7) { | |
| const result = validateDay(t); | |
| return result; | |
| } | |
| if (isDayAfterBooked(day, daysToBlock)) { | |
| return [false, "maintenance", "Cleaning day"]; | |
| } | |
| return validateDay(t); | |
| }; | |
| const isDayAfterBooked = (day, daysToBlock) => { | |
| if (JetABAFData.booked_dates.includes(day.format("YYYY-MM-DD"))) { | |
| return false; | |
| } | |
| for (let i = 1; i <= daysToBlock; i++) { | |
| const previousDay = day.clone().subtract(i, "day").format("YYYY-MM-DD"); | |
| if (JetABAFData.booked_dates.includes(previousDay)) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| return config; | |
| } | |
| const daysToBlock = 3; | |
| window.JetPlugins.hooks.addFilter("jet-booking.input.config", "jetBooking", (config) => | |
| handleBlockedDates(config, daysToBlock) | |
| ); | |
| window.JetPlugins.hooks.addFilter("jet-booking.calendar.config", "jetBookingCalendar", (config) => | |
| handleBlockedDates(config, daysToBlock) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function handleBlockedDates(config, daysToBlock) { | |
| const validateDay = config.beforeShowDay; | |
| config.beforeShowDay = function (t) { | |
| const day = moment(t); | |
| const value = jQuery("[data-field-name='_capacity']:checked").val(); | |
| if (value == 7) { | |
| const result = validateDay(t); | |
| return result; | |
| } | |
| if (isDayNearBooked(day, daysToBlock)) { | |
| return [false, "maintenance", "Cleaning day"]; | |
| } | |
| return validateDay(t); | |
| }; | |
| const isDayNearBooked = (day, daysToBlock) => { | |
| if (JetABAFData.booked_dates.includes(day.format("YYYY-MM-DD"))) { | |
| return false; | |
| } | |
| for (let i = -daysToBlock; i <= daysToBlock; i++) { | |
| const adjacentDay = day.clone().add(i, "day").format("YYYY-MM-DD"); | |
| if (JetABAFData.booked_dates.includes(adjacentDay)) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| }; | |
| return config; | |
| } | |
| const daysToBlock = 3; // Adjust the number of days to block as needed | |
| window.JetPlugins.hooks.addFilter("jet-booking.input.config", "jetBooking", (config) => | |
| handleBlockedDates(config, daysToBlock) | |
| ); | |
| window.JetPlugins.hooks.addFilter("jet-booking.calendar.config", "jetBookingCalendar", (config) => | |
| handleBlockedDates(config, daysToBlock) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment