__('Confirmed','eventqora'),'pending_payment'=>__('Payment pending','eventqora'),'cancelled'=>__('Cancelled','eventqora'),'expired'=>__('Expired','eventqora'),'refunded'=>__('Refunded','eventqora'),'pending'=>__('Pending','eventqora')];return $labels[$status]??ucwords(str_replace('_',' ',(string)$status));} function evqra_sc_my_bookings($atts=[]){evqra_sc_booking_assets();$atts=shortcode_atts(['status'=>'all','limit'=>20,'show_stats'=>'true','show_cancel'=>'true','show_payment'=>'true','show_event'=>'true'],$atts,'evqra_my_bookings');if(!is_user_logged_in())return '

'.esc_html__('Sign in to view your bookings','eventqora').'

'.esc_html__('Your booking dashboard is available after you sign in.','eventqora').'

'.esc_html__('Sign in','eventqora').'
';$limit=max(1,min(100,absint($atts['limit'])));$allowed=['all','confirmed','pending_payment','cancelled','expired','refunded','pending'];$status_filter=in_array($atts['status'],$allowed,true)?$atts['status']:'all';$meta_query=[['key'=>'_evqra_booking_user_id','value'=>get_current_user_id(),'compare'=>'=','type'=>'NUMERIC']];if($status_filter!=='all')$meta_query[]=['key'=>'_evqra_booking_status','value'=>$status_filter,'compare'=>'='];$bookings=get_posts(['post_type'=>'evqra_booking','post_status'=>'publish','posts_per_page'=>$limit,'orderby'=>'date','order'=>'DESC','meta_query'=>$meta_query]);$counts=['confirmed'=>0,'pending_payment'=>0,'cancelled'=>0,'other'=>0];$confirmed_spend=0.0;foreach($bookings as $booking){$status=sanitize_key(get_post_meta($booking->ID,'_evqra_booking_status',true)?:'pending');if(isset($counts[$status]))$counts[$status]++;else$counts['other']++;if($status==='confirmed')$confirmed_spend+=(float)get_post_meta($booking->ID,'_evqra_total_price',true);}ob_start();echo '
';if(evqra_sc_bool($atts['show_stats'],true))echo '
'.esc_html(number_format_i18n(array_sum($counts))).''.esc_html__('Bookings shown','eventqora').'
'.esc_html(number_format_i18n($counts['confirmed'])).''.esc_html__('Confirmed','eventqora').'
'.esc_html(number_format_i18n($counts['pending_payment'])).''.esc_html__('Payment pending','eventqora').'
'.esc_html(number_format_i18n($confirmed_spend,2)).''.esc_html__('Confirmed spend','eventqora').'
';if(!$bookings){echo '

'.esc_html__('No bookings found','eventqora').'

'.esc_html__('Your bookings will appear here after you reserve an event.','eventqora').'

';return ob_get_clean();}echo '
';foreach($bookings as $booking){$booking_id=$booking->ID;$status=sanitize_key(get_post_meta($booking_id,'_evqra_booking_status',true)?:'pending');$payment_status=sanitize_key(get_post_meta($booking_id,'_evqra_payment_status',true)?:'pending');$event_id=absint(get_post_meta($booking_id,'_evqra_booking_event_id',true));$event=$event_id?get_post($event_id):null;$event_url=$event?get_permalink($event_id):'';$event_title=$event?get_the_title($event_id):__('Event no longer available','eventqora');$event_image=$event&&has_post_thumbnail($event_id)?get_the_post_thumbnail_url($event_id,'medium'):'';$quantity=max(1,absint(get_post_meta($booking_id,'_evqra_booking_quantity',true)));$ticket_title=sanitize_text_field(get_post_meta($booking_id,'_evqra_booking_ticket_title',true));$total=(float)get_post_meta($booking_id,'_evqra_total_price',true);$is_paid=$payment_status==='paid'&&$total>0;$display_status=($status==='confirmed'&&$is_paid)?__('Payment completed','eventqora'):(($status==='pending_payment'&&$is_paid)?__('Payment received — confirmation pending','eventqora'):evqra_sc_booking_status_label($status));$currency=strtoupper(sanitize_text_field(get_post_meta($booking_id,'_evqra_currency',true)?:get_option('evqra_currency','USD')));$start=$event_id&&class_exists('EVQRA_Core')?EVQRA_Core::event_datetime($event_id,'start'):null;echo '
';if(evqra_sc_bool($atts['show_event'],true))echo ''.($event_image?'':'').'';echo '
'.esc_html($display_status).'#'.esc_html($booking_id).'
';if(evqra_sc_bool($atts['show_event'],true))echo '

'.esc_html($event_title).'

';echo '
';if($start)echo '◷ '.esc_html(wp_date(get_option('date_format'),$start->getTimestamp(),class_exists('EVQRA_Core')?EVQRA_Core::event_timezone($event_id):wp_timezone())).'';echo '🎟 '.esc_html($ticket_title?:__('Ticket','eventqora')).' × '.esc_html($quantity).'◆ '.esc_html($currency.' '.number_format($total,2)).'
';if($event_url)echo ''.esc_html__('View event','eventqora').'';if($status==='pending_payment'&&!$is_paid&&evqra_sc_bool($atts['show_payment'],true)){ $payment_page_id=absint(get_option('evqra_payment_page_id'));$payment_url=$payment_page_id?get_permalink($payment_page_id):home_url('/payment-process/');$mode=get_option('evqra_paypal_mode','sandbox')==='live'?'live':'sandbox';$paypal_ready=get_option('evqra_paypal_'.$mode.'_client_id','')&&get_option('evqra_paypal_'.$mode.'_secret','');if($paypal_ready){$payment_url=add_query_arg(['evqra_process_payment'=>'yes','booking_id'=>$booking_id,'gateway'=>'paypal','evqra_payment_token'=>class_exists('EVQRA_Core')?EVQRA_Core::payment_token($booking_id):''],$payment_url);echo ''.esc_html__('Complete payment','eventqora').'';}}if(evqra_sc_bool($atts['show_cancel'],true)&&in_array($status,['confirmed','pending_payment'],true))echo '
'.wp_kses_post(wp_nonce_field('evqra_cancel_booking_action','evqra_cancel_booking_nonce',true,false)).'
';echo '
';}echo '
';return ob_get_clean();} add_action('init',function(){add_shortcode('evqra_my_bookings','evqra_sc_my_bookings');add_shortcode('evqra_bookings','evqra_sc_my_bookings');},101); add_action('template_redirect',function(){ $request_method = strtoupper(sanitize_text_field(wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_SPECIAL_CHARS) ?: ''))); $booking_id=absint(filter_input(INPUT_POST, 'evqra_cancel_booking_id', FILTER_SANITIZE_SPECIAL_CHARS) ?: 0); if($request_method!=='POST'||!$booking_id||!is_user_logged_in())return; $nonce=sanitize_text_field(wp_unslash(filter_input(INPUT_POST, 'evqra_cancel_booking_nonce', FILTER_SANITIZE_SPECIAL_CHARS) ?: '')); if(!$booking_id||!wp_verify_nonce($nonce,'evqra_cancel_booking_action'))return; $booking=get_post($booking_id); $owner=absint(get_post_meta($booking_id,'_evqra_booking_user_id',true)); if(!$booking||$booking->post_type!=='evqra_booking'||$owner!==get_current_user_id())return; if(!class_exists('EVQRA_Cancellation_Manager'))return; $result=EVQRA_Cancellation_Manager::cancel_booking($booking_id,get_current_user_id()); if(is_wp_error($result))return; wp_safe_redirect(wp_get_referer()?:home_url('/my-bookings/')); exit; },5);