ID; global $post; if($post and $post->post_type == $this->get_main_post_type()) $translated_event_id = $post->ID; else $translated_event_id = $event_id; $tickets = isset($event->data->tickets) ? $event->data->tickets : []; $dates = isset($event->dates) ? $event->dates : array($event->date); if(isset($settings['booking_start_from_first_upcoming_date']) && $settings['booking_start_from_first_upcoming_date']) { $maximum_dates = isset($settings['booking_maximum_dates']) && trim($settings['booking_maximum_dates']) ? $settings['booking_maximum_dates'] : 12; list($occurrence, $occurrence_time) = $this->get_start_date_to_get_event_dates($event_id, current_time('Y-m-d')); $dates = $this->getRender()->dates($event_id, $event->data, $maximum_dates, ($occurrence_time ? date('Y-m-d H:i:s', $occurrence_time) : $occurrence)); $dates = $this->adjust_event_dates_for_booking($event, $dates); } $booking_options = get_post_meta($event_id, 'mec_booking', true); if(!is_array($booking_options)) $booking_options = []; // WC System $WC_status = (isset($settings['wc_status']) and $settings['wc_status'] and class_exists('WooCommerce')); $WC_booking_form = (isset($settings['wc_booking_form']) and $settings['wc_booking_form']); if($ticket_id) { $new_tickets = []; foreach($tickets as $t_id => $ticket) { if((int) $t_id === (int) $ticket_id) { $new_tickets[$t_id] = $ticket; } } if(count($new_tickets)) $tickets = $new_tickets; } $occurrence_time = $dates[0]['start']['timestamp'] ?? strtotime($dates[0]['start']['date']); $default_ticket_number = 0; if(count($tickets) == 1) $default_ticket_number = 1; $book = $this->getBook(); $availability = $book->get_tickets_availability($event_id, $occurrence_time); $date_format = (isset($ml_settings['booking_date_format1']) and trim($ml_settings['booking_date_format1'])) ? $ml_settings['booking_date_format1'] : 'Y-m-d'; if(isset($event->data->meta['mec_repeat_type']) and $event->data->meta['mec_repeat_type'] === 'custom_days') $date_format .= ' '.get_option('time_format'); $midnight_event = $this->is_midnight_event($event); $book_all_occurrences = 0; if(isset($event->data) and isset($event->data->meta) and isset($event->data->meta['mec_booking']) and isset($event->data->meta['mec_booking']['bookings_all_occurrences'])) $book_all_occurrences = (int) $event->data->meta['mec_booking']['bookings_all_occurrences']; // User Booking Limits list($user_ticket_limit, $user_ticket_unlimited) = $book->get_user_booking_limit($event_id); // Show Booking Form Interval $show_booking_form_interval = (isset($settings['show_booking_form_interval'])) ? $settings['show_booking_form_interval'] : 0; if(isset($booking_options['show_booking_form_interval']) and trim($booking_options['show_booking_form_interval']) != '') $show_booking_form_interval = $booking_options['show_booking_form_interval']; if($show_booking_form_interval) { $filtered_dates = []; foreach($dates as $date) { $date_diff = $this->date_diff(date('Y-m-d h:i a', current_time('timestamp')), date('Y-m-d h:i a', $date['start']['timestamp'])); if(isset($date_diff->days) and !$date_diff->invert) { $minute = $date_diff->days * 24 * 60; $minute += $date_diff->h * 60; $minute += $date_diff->i; if($minute > $show_booking_form_interval) continue; } $filtered_dates[] = $date; } $dates = $filtered_dates; } $available_spots = 0; $total_spots = -1; foreach($availability as $ticket_id=>$count) { if(!is_numeric($ticket_id)) { $total_spots = $count; continue; } if($count != '-1') $available_spots += $count; else { $available_spots = -1; break; } } if($total_spots > 0) $available_spots = min($available_spots, $total_spots); // Date Selection Method $date_selection = (isset($settings['booking_date_selection']) and trim($settings['booking_date_selection'])) ? $settings['booking_date_selection'] : 'dropdown'; if(isset($settings['booking_date_selection_per_event']) and $settings['booking_date_selection_per_event'] and isset($booking_options['bookings_date_selection']) and trim($booking_options['bookings_date_selection']) and $booking_options['bookings_date_selection'] !== 'global') { $date_selection = $booking_options['bookings_date_selection']; } // Omit End Dates $omit_end_dates = isset($settings['booking_omit_end_date']) && $settings['booking_omit_end_date']; // Modal Booking $modal_booking = isset($_GET['method']) && sanitize_text_field($_GET['method']) === 'mec-booking-modal'; wp_enqueue_script('mec-niceselect-script'); ?>