Changeset 3406344
- Timestamp:
- 11/30/2025 11:24:52 PM (4 months ago)
- Location:
- product-add-ons-custom-fields-booking-extra-options-for-woocommerce
- Files:
-
- 18 deleted
- 4 edited
-
tags/1.1.0/includes/front/js/paocfbfw_front.js (modified) (1 diff)
-
tags/1.1.0/readme.txt (modified) (1 diff)
-
tags/1.1.0/vendor/freemius/LICENSE.txt (deleted)
-
tags/1.1.0/vendor/freemius/assets (deleted)
-
tags/1.1.0/vendor/freemius/config.php (deleted)
-
tags/1.1.0/vendor/freemius/includes (deleted)
-
tags/1.1.0/vendor/freemius/index.php (deleted)
-
tags/1.1.0/vendor/freemius/languages (deleted)
-
tags/1.1.0/vendor/freemius/require.php (deleted)
-
tags/1.1.0/vendor/freemius/start.php (deleted)
-
tags/1.1.0/vendor/freemius/templates (deleted)
-
trunk/includes/front/js/paocfbfw_front.js (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/vendor/freemius/LICENSE.txt (deleted)
-
trunk/vendor/freemius/assets (deleted)
-
trunk/vendor/freemius/config.php (deleted)
-
trunk/vendor/freemius/includes (deleted)
-
trunk/vendor/freemius/index.php (deleted)
-
trunk/vendor/freemius/languages (deleted)
-
trunk/vendor/freemius/require.php (deleted)
-
trunk/vendor/freemius/start.php (deleted)
-
trunk/vendor/freemius/templates (deleted)
Legend:
- Unmodified
- Added
- Removed
-
product-add-ons-custom-fields-booking-extra-options-for-woocommerce/tags/1.1.0/includes/front/js/paocfbfw_front.js
r3387033 r3406344 38 38 39 39 // Datepicker initialization 40 40 /* <fs_premium_only> */ 41 42 const calendarContainer = $("#paocfbfw_calendar"); 43 const bookingField = $("#paocfbfw_calendar_field"); 44 let bookedDays = []; // Store booked days for the current month 45 46 47 if (calendarContainer.length) { 48 // Set default date to today in text input 49 const today = new Date(); 50 const formattedDate = $.datepicker.formatDate(paocfbfw_customBookingAjax.date_format, today); 51 bookingField.val(formattedDate); 52 53 // Function to fetch booked days for the given month, year, and product ID 54 function fetchBookedDays(year, month, productId) { 55 $.ajax({ 56 url: paocfbfw_customBookingAjax.ajax_url, 57 type: "POST", 58 data: { 59 action: "fetch_booked_days", 60 year: year, 61 month: month, 62 product_id: productId, // Pass product ID 63 }, 64 dataType: "json", 65 success: function (response) { 66 if (response.success && Array.isArray(response.data.booked_days)) { 67 // console.log(response.data.booked_days); 68 bookedDays = response.data.booked_days.map(Number); // Ensure numeric values 69 calendarContainer.datepicker("refresh"); // Refresh the datepicker UI 70 } else { 71 console.error("Invalid response for booked days."); 72 } 73 }, 74 error: function () { 75 console.error("Failed to fetch booked days."); 76 }, 77 }); 78 } 79 80 if(paocfbfw_customBookingAjax.show_calendar_input == 'on'){ 81 bookingField.show(); 82 }else{ 83 bookingField.hide(); 84 } 85 86 // Initialize the Datepicker 87 if (calendarContainer.length) { 88 const productId = calendarContainer.data("product-id"); // Assume product ID is passed in a data attribute 89 90 calendarContainer.datepicker({ 91 dateFormat: paocfbfw_customBookingAjax.date_format, 92 changeMonth: true, 93 changeYear: true, 94 // defaultDate: paocfbfw_customBookingAjax.start_date, // Default date, can be adjusted 95 minDate: paocfbfw_customBookingAjax.start_date, // Disallow past dates 96 maxDate: paocfbfw_customBookingAjax.end_date, // Allow booking up to 1 year in advance, 97 98 99 onSelect: function (dateText) { 100 bookingField.val(dateText); // Update the hidden input field 101 }, 102 onChangeMonthYear: function (year, month, obj) { 103 fetchBookedDays(year, month, productId); // Load booked days for the newly displayed month 104 }, 105 beforeShowDay: function (date) { 106 const day = date.getDate(); 107 const today = new Date(); 108 today.setHours(0, 0, 0, 0); 109 const isPastDate = date < today; 110 const isBooked = bookedDays.includes(day); 111 112 // Return [true/false, className, tooltipText] 113 if (isPastDate) { 114 return [false, "past-day", "Not Available"]; 115 } 116 if (isBooked) { 117 return [false, "booked-day", "Booked"]; 118 } 119 const startDate = $.datepicker.parseDate(paocfbfw_customBookingAjax.date_format, paocfbfw_customBookingAjax.start_date); 120 const endDate = $.datepicker.parseDate(paocfbfw_customBookingAjax.date_format, paocfbfw_customBookingAjax.end_date); 121 122 // If the date is not in min and max range, disable it and return "Not Available" 123 // console.log(endDate); 124 if(startDate !== null || endDate !== null){ 125 if (date < startDate || date > endDate) { 126 return [false, "out-of-range-day", "Not Available"]; 127 } 128 } 129 130 // Otherwise, return true for available dates 131 return [true, "", "Available"]; 132 }, 133 }); 134 135 // Fetch booked days for the initial month 136 const currentDate = calendarContainer.datepicker("getDate") || new Date(); 137 fetchBookedDays(currentDate.getFullYear(), currentDate.getMonth() + 1, productId); 138 } 139 // bookingField.keydown(function (e) { 140 // e.preventDefault(); 141 // }); 142 143 bookingField.on("keyup", function () { 144 145 const dateText = $(this).val(); // Get the input value 146 const dateFormat = paocfbfw_customBookingAjax.date_format; // Get the format from paocfbfw_customBookingAjax 147 148 try { 149 // Parse the entered date using the datepicker's parseDate method 150 const parsedDate = $.datepicker.parseDate(dateFormat, dateText); 151 // Check if the selected date is booked 152 const day = parsedDate.getDate(); 153 if (bookedDays.includes(day)) { 154 alert("This date is already booked. Please select another date."); 155 $(this).val(""); // Clear the input field 156 return; 157 } 158 // If valid, set the date in the datepicker 159 calendarContainer.datepicker("setDate", parsedDate); 160 } catch (e) { 161 alert("Invalid date format. Please use the correct format."); 162 $(this).val(""); // Clear the input field if the date is invalid 163 } 164 }); 165 166 } 167 /* </fs_premium_only> */ 41 168 42 169 //handle price change on date selection -
product-add-ons-custom-fields-booking-extra-options-for-woocommerce/tags/1.1.0/readme.txt
r3387036 r3406344 3 3 Tags: woocommerce-product-addons, woocommerce-product-options, woocommerce-custom-fields, booking-calendar, woocommerce-file-upload 4 4 Requires at least: 5.3 5 Tested up to: 6. 85 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 7 Stable tag: 1.1.0 -
product-add-ons-custom-fields-booking-extra-options-for-woocommerce/trunk/includes/front/js/paocfbfw_front.js
r3328965 r3406344 38 38 39 39 // Datepicker initialization 40 40 /* <fs_premium_only> */ 41 42 const calendarContainer = $("#paocfbfw_calendar"); 43 const bookingField = $("#paocfbfw_calendar_field"); 44 let bookedDays = []; // Store booked days for the current month 45 46 47 if (calendarContainer.length) { 48 // Set default date to today in text input 49 const today = new Date(); 50 const formattedDate = $.datepicker.formatDate(paocfbfw_customBookingAjax.date_format, today); 51 bookingField.val(formattedDate); 52 53 // Function to fetch booked days for the given month, year, and product ID 54 function fetchBookedDays(year, month, productId) { 55 $.ajax({ 56 url: paocfbfw_customBookingAjax.ajax_url, 57 type: "POST", 58 data: { 59 action: "fetch_booked_days", 60 year: year, 61 month: month, 62 product_id: productId, // Pass product ID 63 }, 64 dataType: "json", 65 success: function (response) { 66 if (response.success && Array.isArray(response.data.booked_days)) { 67 // console.log(response.data.booked_days); 68 bookedDays = response.data.booked_days.map(Number); // Ensure numeric values 69 calendarContainer.datepicker("refresh"); // Refresh the datepicker UI 70 } else { 71 console.error("Invalid response for booked days."); 72 } 73 }, 74 error: function () { 75 console.error("Failed to fetch booked days."); 76 }, 77 }); 78 } 79 80 if(paocfbfw_customBookingAjax.show_calendar_input == 'on'){ 81 bookingField.show(); 82 }else{ 83 bookingField.hide(); 84 } 85 86 // Initialize the Datepicker 87 if (calendarContainer.length) { 88 const productId = calendarContainer.data("product-id"); // Assume product ID is passed in a data attribute 89 90 calendarContainer.datepicker({ 91 dateFormat: paocfbfw_customBookingAjax.date_format, 92 changeMonth: true, 93 changeYear: true, 94 // defaultDate: paocfbfw_customBookingAjax.start_date, // Default date, can be adjusted 95 minDate: paocfbfw_customBookingAjax.start_date, // Disallow past dates 96 maxDate: paocfbfw_customBookingAjax.end_date, // Allow booking up to 1 year in advance, 97 98 99 onSelect: function (dateText) { 100 bookingField.val(dateText); // Update the hidden input field 101 }, 102 onChangeMonthYear: function (year, month, obj) { 103 fetchBookedDays(year, month, productId); // Load booked days for the newly displayed month 104 }, 105 beforeShowDay: function (date) { 106 const day = date.getDate(); 107 const today = new Date(); 108 today.setHours(0, 0, 0, 0); 109 const isPastDate = date < today; 110 const isBooked = bookedDays.includes(day); 111 112 // Return [true/false, className, tooltipText] 113 if (isPastDate) { 114 return [false, "past-day", "Not Available"]; 115 } 116 if (isBooked) { 117 return [false, "booked-day", "Booked"]; 118 } 119 const startDate = $.datepicker.parseDate(paocfbfw_customBookingAjax.date_format, paocfbfw_customBookingAjax.start_date); 120 const endDate = $.datepicker.parseDate(paocfbfw_customBookingAjax.date_format, paocfbfw_customBookingAjax.end_date); 121 122 // If the date is not in min and max range, disable it and return "Not Available" 123 // console.log(endDate); 124 if(startDate !== null || endDate !== null){ 125 if (date < startDate || date > endDate) { 126 return [false, "out-of-range-day", "Not Available"]; 127 } 128 } 129 130 // Otherwise, return true for available dates 131 return [true, "", "Available"]; 132 }, 133 }); 134 135 // Fetch booked days for the initial month 136 const currentDate = calendarContainer.datepicker("getDate") || new Date(); 137 fetchBookedDays(currentDate.getFullYear(), currentDate.getMonth() + 1, productId); 138 } 139 // bookingField.keydown(function (e) { 140 // e.preventDefault(); 141 // }); 142 143 bookingField.on("keyup", function () { 144 145 const dateText = $(this).val(); // Get the input value 146 const dateFormat = paocfbfw_customBookingAjax.date_format; // Get the format from paocfbfw_customBookingAjax 147 148 try { 149 // Parse the entered date using the datepicker's parseDate method 150 const parsedDate = $.datepicker.parseDate(dateFormat, dateText); 151 // Check if the selected date is booked 152 const day = parsedDate.getDate(); 153 if (bookedDays.includes(day)) { 154 alert("This date is already booked. Please select another date."); 155 $(this).val(""); // Clear the input field 156 return; 157 } 158 // If valid, set the date in the datepicker 159 calendarContainer.datepicker("setDate", parsedDate); 160 } catch (e) { 161 alert("Invalid date format. Please use the correct format."); 162 $(this).val(""); // Clear the input field if the date is invalid 163 } 164 }); 165 166 } 167 /* </fs_premium_only> */ 41 168 42 169 //handle price change on date selection -
product-add-ons-custom-fields-booking-extra-options-for-woocommerce/trunk/readme.txt
r3387036 r3406344 3 3 Tags: woocommerce-product-addons, woocommerce-product-options, woocommerce-custom-fields, booking-calendar, woocommerce-file-upload 4 4 Requires at least: 5.3 5 Tested up to: 6. 85 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 7 Stable tag: 1.1.0
Note: See TracChangeset
for help on using the changeset viewer.