Plugin Directory

Changeset 3406344


Ignore:
Timestamp:
11/30/2025 11:24:52 PM (4 months ago)
Author:
wpsaad
Message:

wp update

Location:
product-add-ons-custom-fields-booking-extra-options-for-woocommerce
Files:
18 deleted
4 edited

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  
    3838
    3939    // Datepicker initialization
    40    
     40    /* <fs_premium_only> */
     41
     42const calendarContainer = $("#paocfbfw_calendar");
     43const bookingField = $("#paocfbfw_calendar_field");
     44let bookedDays = []; // Store booked days for the current month
     45
     46
     47if (calendarContainer.length) {
     48    // Set default date to today in text input
     49const today = new Date();
     50const formattedDate = $.datepicker.formatDate(paocfbfw_customBookingAjax.date_format, today);
     51bookingField.val(formattedDate);
     52
     53        // Function to fetch booked days for the given month, year, and product ID
     54function 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
     80if(paocfbfw_customBookingAjax.show_calendar_input == 'on'){
     81    bookingField.show();
     82}else{
     83    bookingField.hide();
     84}
     85
     86// Initialize the Datepicker
     87if (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
     143bookingField.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> */
    41168
    42169//handle price change on date selection
  • product-add-ons-custom-fields-booking-extra-options-for-woocommerce/tags/1.1.0/readme.txt

    r3387036 r3406344  
    33Tags: woocommerce-product-addons, woocommerce-product-options, woocommerce-custom-fields, booking-calendar, woocommerce-file-upload
    44Requires at least: 5.3
    5 Tested up to: 6.8
     5Tested up to: 6.9
    66Requires PHP: 7.4
    77Stable tag: 1.1.0
  • product-add-ons-custom-fields-booking-extra-options-for-woocommerce/trunk/includes/front/js/paocfbfw_front.js

    r3328965 r3406344  
    3838
    3939    // Datepicker initialization
    40    
     40    /* <fs_premium_only> */
     41
     42const calendarContainer = $("#paocfbfw_calendar");
     43const bookingField = $("#paocfbfw_calendar_field");
     44let bookedDays = []; // Store booked days for the current month
     45
     46
     47if (calendarContainer.length) {
     48    // Set default date to today in text input
     49const today = new Date();
     50const formattedDate = $.datepicker.formatDate(paocfbfw_customBookingAjax.date_format, today);
     51bookingField.val(formattedDate);
     52
     53        // Function to fetch booked days for the given month, year, and product ID
     54function 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
     80if(paocfbfw_customBookingAjax.show_calendar_input == 'on'){
     81    bookingField.show();
     82}else{
     83    bookingField.hide();
     84}
     85
     86// Initialize the Datepicker
     87if (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
     143bookingField.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> */
    41168
    42169//handle price change on date selection
  • product-add-ons-custom-fields-booking-extra-options-for-woocommerce/trunk/readme.txt

    r3387036 r3406344  
    33Tags: woocommerce-product-addons, woocommerce-product-options, woocommerce-custom-fields, booking-calendar, woocommerce-file-upload
    44Requires at least: 5.3
    5 Tested up to: 6.8
     5Tested up to: 6.9
    66Requires PHP: 7.4
    77Stable tag: 1.1.0
Note: See TracChangeset for help on using the changeset viewer.