Booking slot interval bug

I have several users who advertise by “shift”. In this case, they put a booking slot interval of 1 hour (60 minutes) between one shift and another. However, for example, if the listing works from 9am to 1pm and from 2pm to 6pm (each shift duration is 240 minutes), when you put “60” minutes in the “booking slot interval” field, the afternoon shift does not appear in the listing. It always appeared and a few days ago I noticed that the afternoon shifts with a 60-minute interval for ALL users disappeared. I tested an interval of 30 minutes and it worked, more than that it doesn’t show the afternoon shift. It’s as if the system itself allowed a maximum booking slot interval of just 30 minutes between one reservation and the next. What is happening? Please, I need help. See images below:

1) BOOKING SLOT INTERVAL - 60-MINUTE (THE BUG):

  • How it appears in the listing (THE BUG):

2) BOOKING SLOT INTERVAL - 30-MINUTE (IT IS WORKING CORRECTLY):

  • How it appears in the listing (IT IS WORKING CORRECTLY:

Hi,

Thanks for reporting this, the bug is confirmed, and we’ll fix it as soon as possible.

As a temporary solution, please try to set Booking Available To - 19:00 and Booking Slot Duration 240.

Thanks a lot for the quick feedback.

In this case, I will wait for the solution, as I would need to edit more than 200 listings.

Hi Nicole,

Nice website. However, I noticed your google log in and other social media log in are not working. If you need help setting them up let me know and I can walk you through it.

2 Likes

Thanks, I will check (:

Hello, Andrii!

Is there any prediction for the bug to be rectified?
As I mentioned, I have more than 200 listings registered, which makes it impossible to use the provisional alternative you suggested.

I am concerned that my customers are losing bookings because of this bug.

Thank you so much in advance!

Please send temporary WP access link via email support@hivepress.io using this plugin Temporary Login Without Password – WordPress plugin | WordPress.org and we’ll debug this further. If there’s a temporary code fix before the official release, we’ll make it directly on your site.

1 Like

Hi,

Please try this PHP snippet (How to add custom code snippets - HivePress Help Center):

add_filter(
 'hivepress/v1/routes',
 function($routes){
  if(isset($routes['listing_slots_resource'])){
   $routes['listing_slots_resource']['action'] = function( $request){
    
   // Check permissions.
   if ( ! get_option( 'hp_booking_enable_time' ) ) {
    return;
   }

   // Get date time.
   $date_time = strtotime( $request->get_param( 'parent_value' ) );

   if ( !$date_time ) {
    return hivepress()->helper->rest_response( 200, [] );
   }

   // Get listing.
   $listing = \HivePress\Models\Listing::query()->get_by_id( $request->get_param( 'listing_id' ) );

   if ( !$listing  ! hivepress()->booking->is_booking_enabled( $listing )  ! hivepress()->booking->is_time_enabled( $listing ) ) {
    return hivepress()->helper->rest_error( 404 );
   }

   if ( is_null( $listing->get_booking_min_time() )  is_null( $listing->get_booking_max_time() )  ! $listing->get_booking_slot_duration() ) {
    return hivepress()->helper->rest_error( 400 );
   }

   // Get time format.
   $time_format = get_option( 'time_format' );

   // Get time range.
   $current_time = hivepress()->booking->get_shifted_time( $listing, time() );
   $start_time   = $listing->get_booking_min_time();
   $max_time     = $listing->get_booking_max_time() ? $listing->get_booking_max_time() : DAY_IN_SECONDS;

   if ( $start_time > $max_time ) {
    $max_time += DAY_IN_SECONDS;
   }

   // Get booked times.
   $booked_times = array_map(
    function( $booking ) use ( $date_time ) {
     return [
      $booking->get_start_time() - $date_time,
      $booking->get_end_time() - $date_time,
      $booking->get_status(),
      $booking->get_quantity(),
     ];
    },
    \HivePress\Models\Booking::query()->filter(
     [
      'listing__in'     => hivepress()->booking->get_listing_ids( $listing ),
      'status__in'      => hivepress()->booking->get_blocked_statuses(),
      'start_time__gte' => $date_time,
      'start_time__lt'  => $date_time + DAY_IN_SECONDS,
     ]
    )->get()
    ->serialize()
   );

   // Get results.
   $results = [];

   $is_multiple = get_option( 'hp_booking_enable_capacity' ) && $listing->get_booking_max_quantity();

   while ( $start_time < $max_time + $listing->get_booking_slot_interval() * 60 ) {
    // Get end time.
    $end_time = $start_time + ( $listing->get_booking_slot_duration() + $listing->get_booking_slot_interval() ) * 60;

    if ( $end_time > $max_time + $listing->get_booking_slot_interval() * 60 ) {
     break;
    }

    // Get booking count.
    $booking_count = 0;

    foreach ( $booked_times as $booked_time ) {
     if ( ( $start_time >= $booked_time[0] && $start_time < $booked_time[1] )  ( $end_time > $booked_time[0] && $end_time <= $booked_time[1] )  ( $start_time < $booked_time[0] && $end_time > $booked_time[1] ) ) {
      if ( 'private' === $booked_time[2] ) {
       $booking_count = 1000000;

       break;
      } elseif ( $is_multiple ) {
       $booking_count += $booked_time[3];
      } else {
       $booking_count++;
      }

      if ( ! $is_multiple ) {
       break;
      }
     }
    }

    // Check availability.
    $is_booked = (bool) $booking_count;

    if ( $is_multiple ) {
     $is_booked = $booking_count >= $listing->get_booking_max_quantity();
    }

    if ( ! $is_booked ) {

     // Get slot time.
     $slot_time = $date_time + $start_time;

     if ( $slot_time > $current_time ) {

      // Add result.
      $results[] = [
       'id'   => $start_time,
       'text' => date_i18n( $time_format, $slot_time ) . ' - ' . date_i18n( $time_format, $slot_time + $listing->get_booking_slot_duration() * 60 ),
      ];
     }
    }

    $start_time = $end_time;
   }

   return hivepress()->helper->rest_response( 200, $results );
   };
  }
  return $routes;
 },
 1000
);
1 Like

Hello, Andri.

I did a test by adding the code directly to the function.php file

And the site returned a critical/fatal error.

ERRO:
syntax error, unexpected '!' in /srv/htdocs/wp-content/themes/rentalhive/functions.php on line 29

LINE ERROR:

if ( !$listing  ! hivepress()->booking->is_booking_enabled( $listing )  ! hivepress()->booking->is_time_enabled( $listing ) ) {
       return hivepress()->helper->rest_error( 404 );
}

Can you tell me what is the error pointed by wordpress? And help me?

Please try this PHP snippet instead. Please use the Code Snippets plugin to add and manage custom PHP code snippets Code Snippets – WordPress plugin | WordPress.org

add_filter(
	'hivepress/v1/routes',
	function($routes){
		if(isset($routes['listing_slots_resource'])){
			$routes['listing_slots_resource']['action'] = function( $request){
				
			// Check permissions.
			if ( ! get_option( 'hp_booking_enable_time' ) ) {
				return;
			}

			// Get date time.
			$date_time = strtotime( $request->get_param( 'parent_value' ) );

			if ( !$date_time ) {
				return hivepress()->helper->rest_response( 200, [] );
			}

			// Get listing.
			$listing = \HivePress\Models\Listing::query()->get_by_id( $request->get_param( 'listing_id' ) );

			if ( !$listing || ! hivepress()->booking->is_booking_enabled( $listing ) || ! hivepress()->booking->is_time_enabled( $listing ) ) {
				return hivepress()->helper->rest_error( 404 );
			}

			if ( is_null( $listing->get_booking_min_time() ) || is_null( $listing->get_booking_max_time() ) || ! $listing->get_booking_slot_duration() ) {
				return hivepress()->helper->rest_error( 400 );
			}

			// Get time format.
			$time_format = get_option( 'time_format' );

			// Get time range.
			$current_time = hivepress()->booking->get_shifted_time( $listing, time() );
			$start_time   = $listing->get_booking_min_time();
			$max_time     = $listing->get_booking_max_time() ? $listing->get_booking_max_time() : DAY_IN_SECONDS;

			if ( $start_time > $max_time ) {
				$max_time += DAY_IN_SECONDS;
			}

			// Get booked times.
			$booked_times = array_map(
				function( $booking ) use ( $date_time ) {
					return [
						$booking->get_start_time() - $date_time,
						$booking->get_end_time() - $date_time,
						$booking->get_status(),
						$booking->get_quantity(),
					];
				},
				\HivePress\Models\Booking::query()->filter(
					[
						'listing__in'     => hivepress()->booking->get_listing_ids( $listing ),
						'status__in'      => hivepress()->booking->get_blocked_statuses(),
						'start_time__gte' => $date_time,
						'start_time__lt'  => $date_time + DAY_IN_SECONDS,
					]
				)->get()
				->serialize()
			);

			// Get results.
			$results = [];

			$is_multiple = get_option( 'hp_booking_enable_capacity' ) && $listing->get_booking_max_quantity();

			while ( $start_time < $max_time + $listing->get_booking_slot_interval() * 60 ) {
				// Get end time.
				$end_time = $start_time + ( $listing->get_booking_slot_duration() + $listing->get_booking_slot_interval() ) * 60;

				if ( $end_time > $max_time + $listing->get_booking_slot_interval() * 60 ) {
					break;
				}

				// Get booking count.
				$booking_count = 0;

				foreach ( $booked_times as $booked_time ) {
					if ( ( $start_time >= $booked_time[0] && $start_time < $booked_time[1] ) || ( $end_time > $booked_time[0] && $end_time <= $booked_time[1] ) || ( $start_time < $booked_time[0] && $end_time > $booked_time[1] ) ) {
						if ( 'private' === $booked_time[2] ) {
							$booking_count = 1000000;

							break;
						} elseif ( $is_multiple ) {
							$booking_count += $booked_time[3];
						} else {
							$booking_count++;
						}

						if ( ! $is_multiple ) {
							break;
						}
					}
				}

				// Check availability.
				$is_booked = (bool) $booking_count;

				if ( $is_multiple ) {
					$is_booked = $booking_count >= $listing->get_booking_max_quantity();
				}

				if ( ! $is_booked ) {

					// Get slot time.
					$slot_time = $date_time + $start_time;

					if ( $slot_time > $current_time ) {

						// Add result.
						$results[] = [
							'id'   => $start_time,
							'text' => date_i18n( $time_format, $slot_time ) . ' - ' . date_i18n( $time_format, $slot_time + $listing->get_booking_slot_duration() * 60 ),
						];
					}
				}

				$start_time = $end_time;
			}

			return hivepress()->helper->rest_response( 200, $results );
			};
		}
		return $routes;
	},
	1000
);

Hello! Now it worked. Thank you for the temporary alternative. When you have a definitive solution, please let me know.

1 Like