Change partially_book_days to fully_booked_days if partial booked day

483 Views Asked by At

I can not isolate the hook to make a partial_booked day change the day to fully_booked once a customer places an order for that day... I want to only allow one booking per day yet there must be the option to select any hour of the day for start_time (between 8AM and 9PM).

I have tried several Availability settings in the product editor and even by using priorities for multiple selections of hour block or using a buffer, there is no option to create a datepicker output of fully_booked once the customer picks the hour they want to book. (We are delivering product and can only deliver one a day... but there has to be a time to choose when to deliver so we can not make the product Availability block all day "selectable.")

What I have tried:

$booking_form_params = array('ajax_url' => WC()->ajax_url(), 
'i18n_date_partially_booked' => __('This date is unavailable', 
                                'woocommerce-bookings'), 
@uses add_filter( 'booking_form_params' .... );

(this works on the front end perfectly well but the datepicker still allows clicking event if time left in the day) So of course I tried:

$htm .= '.single.single-product td.partial_booked[data-event="click"] *{ 
pointer-events: unset; cursor:not-allowed !important;
background: #c96259!important;}';
wp_register_style( 'codeoctober-entry-set', false );
wp_enqueue_style(   'codeoctober-entry-set' );
wp_add_inline_style( 'codeoctober-entry-set', $htm );
}
@using add_action( 'wp_footer', .... ); and add_action('wp_enqueue_scripts'....);

wp_enqueue_scripts works great and makes the entire day field (td > a div) of calendar turn a nice bright red... But I still have that pesky click available.

So next I tried: Some inline javascript in about a dozen different fashions and each time I tried to .removeClass or .addClass() or even .replace(regex) in hopes that the td anchor would honor my request to remove the bookable class. Results: nada!

If I could remove the bookable class then I am good to go. We just do not want any one to select a day if another customer has booked any block of time (minimum blocks are four hours).

Was hoping it was as simple as this:

add_filter( 'wc_bookings_date_picker_args', 'function-name');
function-name
{   $booked = 
        $wc_bookings_date_picker_args->booking_form->product->get_id() );

    return array(
        'partially_booked_days' => $booked['fully_booked_days'],
    );
}
1

There are 1 best solutions below

0
On

Here is the workaround.

   /**
   * Use inline style to show booked whole day
   * woocommerce_booking_form_get_posted_data  
   * top:87vh;width:502%;z-index:9;box-shadow: 0 15px 20px rgba(0,0,0,.25);
   * @param string $end_date
   * @return array
   */
   add_action( 'wp_enqueue_scripts', 'codeoctober_inline_public_script' );  
function codeoctober_inline_public_script() 
{

$day_booked = true; //codeoctober_booking_day_booked_meta();
if( $day_booked == true ) {

$htm = ''; 
$htm .= '.single.single-product td.partial_booked[data-event="click"] *, .single.single-product td.partial_booked{-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none; pointer-events: none; cursor:not-allowed !important;background: #c96259!important;}';
wp_register_style( 'codeoctober-entry-set', false );
wp_enqueue_style(   'codeoctober-entry-set' );
wp_add_inline_style( 'codeoctober-entry-set', $htm );
}

}  

And then messages customized for event:

/**
 * Woo booking form notices
 * booking_formparams 
 * 
 * @param string $ajax inclusion
 * @return array
 */
add_filter( 'booking_form_params', 'codeoctober_change_partbooking_form_params' );
function codeoctober_change_partbooking_form_params( $booking_form_params ) {

$booking_form_params = array('ajax_url' => WC()->ajax_url(), 
'i18n_date_partially_booked' => __('This date is unavailable', 'woocommerce-bookings'), 
'i18n_start_date' => __('Choose a Start Date', 'woocommerce-bookings'), 
'i18n_end_date' => __('Choose an End Date', 'woocommerce-bookings'), 
'i18n_dates' => __('Dates', 'woocommerce-bookings'), 
'i18n_choose_options' => __('Please select the options for your booking above first', 'woocommerce-bookings'));
/*wp_localize_script('wc-bookings-booking-form', 'booking_form_params', 
    apply_filters('booking_form_params', $booking_form_params));
*/
return $booking_form_params;
}