Created
July 8, 2022 05:51
-
-
Save kartikparmar/a794425f84d20aded74f8cd8a2d402ef to your computer and use it in GitHub Desktop.
Show timeslot note in the dropdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This function will add the note information to its respective timeslots. | |
* | |
* @param array $time_drop_down_array Array of timeslots and its lockout. Key will be timeslot and it contains array with has lockout information. | |
* @param array $extra_information Additional Informations. | |
* @since 1.0 | |
*/ | |
function bkap_time_slot_filter( $time_drop_down_array, $extra_information ) { | |
$product_id = $_POST['post_id']; | |
$current_date = sanitize_text_field( $_POST['current_date'] ); | |
$booking_date = date( 'j-n-Y', strtotime( $current_date ) ); | |
$booking_times = get_post_meta( $product_id, '_bkap_time_settings', true ); | |
$time_format_to_show = $extra_information['time_format_to_show']; | |
$time_drop_down_array_note = array(); | |
foreach ( $time_drop_down_array as $key => $value ) { | |
$note = bkap_get_timeslot_data( $product_id, $booking_date, $value, 'booking_notes', $booking_times ); | |
$time_drop_down_array_note[ $value ] = $note; | |
} | |
return $time_drop_down_array_note; | |
} | |
add_filter( 'bkap_time_slot_filter_after_chronological', 'bkap_time_slot_filter', 10, 2 ); | |
function bkap_get_timeslot_data( $product_id, $date, $time, $data = 'booking_notes', $time_settings = array(), $passed_data = 'time' ) { | |
$information = ''; | |
$slots_list = array(); | |
$time_format = bkap_common::bkap_get_time_format(); | |
if ( empty( $time_settings ) ) { | |
$time_settings = get_post_meta( $product_id, '_bkap_time_settings', true ); | |
} | |
if ( isset( $time_settings[ $date ] ) ) { | |
$slots_list = $time_settings[ $date ]; | |
} else { | |
// check for the weekday. | |
$weekday = date( 'w', strtotime( $date ) ); | |
$booking_weekday = "booking_weekday_$weekday"; | |
if ( is_array( $time_settings ) && count( $time_settings ) > 0 && array_key_exists( $booking_weekday, $time_settings ) ) { | |
$slots_list = $time_settings[ $booking_weekday ]; | |
} | |
} | |
foreach ( $slots_list as $times ) { | |
$from_time_check = date( $time_format, strtotime( $times['from_slot_hrs'] . ':' . $times['from_slot_min'] ) ); | |
$to_time_check = date( $time_format, strtotime( $times['to_slot_hrs'] . ':' . $times['to_slot_min'] ) ); | |
if ( '' !== $to_time_check && '00:00' !== $to_time_check && '12:00 AM' !== $to_time_check ) { | |
$time_check = "$from_time_check - $to_time_check"; | |
} else { | |
$time_check = "$from_time_check"; | |
} | |
switch ( $passed_data ) { | |
case 'time': | |
if ( $time_check === $time ) { | |
$information = $times[ $data ]; | |
if ( '' === $information ) { | |
$information = $time; | |
} | |
} | |
break; | |
case 'booking_notes': | |
$note = $times['booking_notes']; | |
if ( $note != '' ) { | |
if ( $note === $time ) { | |
$information = $time_check; | |
} | |
} else { | |
$information = $time; | |
} | |
break; | |
} | |
} | |
return $information; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment