L
L
LastGeneral2020-12-21 17:23:09
WordPress
LastGeneral, 2020-12-21 17:23:09

How to hide time in woocommerce booking is not possible to book?

Faced such a problem, in the booking calendar the time for which it is impossible to book is displayed, how can I fix this?
Can somehow hide with styles, and with a script
5fe0aed54d291484484856.png

<div class="tile-col">
        <div class="tile">
                ПН
        </div>
        <div class="tile trans">
                21.12
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="1" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="2" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="3" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="4" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="5" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="6" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="7" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="8" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="9" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="10" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="11" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="12" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="13" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="14" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="15" data-state="locked" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="16" data-state="avalible" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="17" data-state="avalible" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="18" data-state="avalible" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="19" data-state="avalible" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="20" data-state="avalible" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="21" data-state="avalible" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="22" data-state="avalible" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="23" data-state="avalible" class="tile">
        </div>
        <div data-day-id="21122020" data-day="21.12" data-day-full="21.12.2020"
        data-time="24" data-state="avalible" class="tile">
        </div>
</div>

private static function getBookingsTimes( $date, $pageId ) {
    $product = self::get_rental_product($pageId);
    // print_r( $product->get_id() );
    // print_r(wc_bookings_get_time_slots( $product, [] ));
    // var_dump($date);

    $result   = array();
    $bookings = WC_Bookings_Controller::get_all_existing_bookings( $product, $date, $date + ( 24 * 60 * 60 ) );
    $booked_hours = array();

    if ( count( $bookings ) ) {
      // print_r( date( 'd.m.Y H:i:s', $bookings[0]->start ) );
      // print_r( date( 'd.m.Y H:i:s', $bookings[0]->end ) );
      foreach ( $bookings as $booking ) {
        $start_hour = date( 'G', $booking->start );
        $end_hour   = date( 'G', $booking->end );
        // var_dump( $start_hour );
        // var_dump( $end_hour );
        for ( $i = $start_hour; $i < $end_hour; $i++ ) {
          array_push( $booked_hours, $i );
        }
      }
    }
    // print_r($booked_hours);

    $blocked_hours = array();
    $availability  = get_option( 'wc_global_booking_availability', true );
    // print_r( $availability );
    foreach ( $availability as $item ) {
      if ( $item['type'] != 'time:range' ) continue;
      // var_dump($item);
      $from = strtotime( $item['from_date'] );
      $to = strtotime( $item['to_date'] . ' ' . $item['to'] );
      // var_dump($from);
      // var_dump($date);
      // var_dump($to);
      if ( $date >= $from && $date <= $to ) {
        $start_hour = date( 'G', strtotime( $item['from_date'] . ' ' . $item['from'] ) );
        $end_hour = date( 'G', strtotime( $item['to_date'] . ' ' . $item['to'] ) );
        // var_dump($start_hour);
        // var_dump($end_hour);
        for ( $i = $start_hour; $i < $end_hour; $i++ ) {
          array_push( $blocked_hours, $i );
        }
      }
    }
    // print_r( $blocked_hours );

    $current_date = date( 'G' );
    // var_dump($current_date);
    $input_date   = date( 'G', $date );
    $current_hour = date( 'H' );
    // var_dump( $current_hour );
    if ( time() >= $date ) {
      for ( $i = 0; $i < 24; $i++ ) {
        // var_dump(date( 'Y-m-d' ) . ' ' . $i);
        $stri = $i;

        if ( $stri < 10 ) {
          $stri = '0' . $stri;
        }
        if ( $date + ( $i * 3600 ) <= strtotime( date( 'Y-m-d H:00:00' ) ) ) {
          array_push( $blocked_hours, $i );
        }
      }
    }

    for ( $i = 1; $i < 25; $i++ ) {
      $status = 'avalible';
      if ( in_array( $i - 1, $booked_hours ) ) {
        $status = 'booked';
      }
      if ( in_array( $i - 1, $blocked_hours ) ) {
        $status = 'locked';
      }
      $result[$i] = array(
        'data'	=> $status//locked, booked
      );
    }

    return $result;
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question