custom Plugin Reschedule bug, error, issue
-
We are using custom on our woo commerce site, the issue that when a client do booking, then he also gets dashboard where the “RESCHEDULE” option is there. We have 3 products(A,B,C) for which we give bookings. For example, a client orders booking product A for the date 29 march 5 pm, now suppose he wants to reschedule booking for date 10 march 5 pm and this slot is already booked which he wants to book, so if he want to book it then it should show him error because it’ll be double booked. But the case here is that since he ordered booking product A, as I mentioned he wanted to reschedule for date 10 march 5 pm, it’ll show him error only if the product is A that was booked by other client on date 10 march 5 pm. If the product will be B or C, then the client who ordered booking product A for date 29 march 5 pm and wants to reschedule for date 10 march 5 pm will be able to reschedule it and it’ll not give him any error. So double booking case is done here. In shortly if the product will be B or C booked by other clients and the client who ordered for date date 29 march 5 pm will be able to reschedule the booking for date 10 march 5 pm and will get no error, if the product already ordered by other client on date 10 march 5 pm will be A and he wants to reschedule it, then error will come.
php code:<?php /** * Plugin Name: Pro WC Booking Reschedule * Plugin URI: https://procoder.ca * Author: Saber Hossen Rabbani * Author URI: https://saberhr.me * Version: 1.0.0 * Text Domain: pro_wc_booking_reschedule */ function pro_wc_booking_reschedule_assets($page) { wp_enqueue_script('pro_booking_reschedule', plugin_dir_url(__FILE__) . '/script.js', ['jquery'], time(), true); wp_localize_script('pro_booking_reschedule', 'data', array('ajax_url' => admin_url('admin-ajax.php'))); } add_action('wp_enqueue_scripts', 'pro_wc_booking_reschedule_assets'); function pro_wc_booking_reschedule_check() { $booking = get_wc_booking(intval($_GET['booking_id'])); $booking_order_product_id = $booking->get_product_id(); //int val $start_date = date('Y-m-d H:i:s', strtotime($_GET['start_date'])); $end_date = date('Y-m-d H:i:s', strtotime($_GET['end_date'])); $booking_id = WC_Bookings_Controller::get_bookings_in_date_range(strtotime($start_date), strtotime($end_date), $booking_order_product_id); echo count($booking_id); exit(); } add_action('wp_ajax_check_reschedule_time', 'pro_wc_booking_reschedule_check'); add_action('wp_ajax_nopriv_check_reschedule_time', 'pro_wc_booking_reschedule_check');
jquery:
;(function ($) { let prev_start_date = new Date($('#start_date').val()); $('#end_date').attr('disabled', 'true'); $('[name="aw_rescedule"]').attr('disabled', 'true'); $('#start_date').on('change', function () { $('[name="aw_rescedule"]').attr('disabled', 'true'); let start_date = new Date($(this).val()); let end_time = new Date($(this).val()); let booking_id = $('#aw_booking_id').val(); end_time.setMinutes(end_time.getMinutes() + 45); $.ajax({ url: data.ajax_url, method: 'get', data: { action: 'check_reschedule_time', start_date: <code>${start_date.getFullYear()}-${start_date.getMonth() + 1}-${start_date.getDate()} ${start_date.getHours()}:${start_date.getMinutes()}:00</code>, end_date: <code>${end_time.getFullYear()}-${end_time.getMonth() + 1}-${end_time.getDate()} ${end_time.getHours()}:${end_time.getMinutes()}:00</code>, booking_id: booking_id }, success: function (res) { console.log(res) if (parseInt(res) < 1) { let month = end_time.getMonth() + 1; if (month < 10) { month = "0" + month; } prev_start_date = start_date; let end_date = <code>${end_time.getFullYear()}/${month}/${end_time.getDate()} ${end_time.getHours()}:${end_time.getMinutes()}</code>; $('#end_date').val(end_date); $('[name="aw_rescedule"]').removeAttr('disabled'); } else { let month = prev_start_date.getMonth() + 1; if (month < 10) { month = "0" + month; } const prev_start_date_format = <code>${prev_start_date.getFullYear()}/${month}/${prev_start_date.getDate()} ${prev_start_date.getHours()}:${prev_start_date.getMinutes()}</code>; $('#start_date').val(prev_start_date_format); $('#start_date').blur(); alert('Sorry, we already have a booking at the time.'); } } }); }); $('[name=aw_rescedule]').on('click', function (e) { $('#end_date').removeAttr('disabled'); return true; }) })(jQuery)
The page I need help with: [log in to see the link]
- The topic ‘custom Plugin Reschedule bug, error, issue’ is closed to new replies.