eventsmanager

My-Bookings Page Template with Booking Ticket List

Apr 27th, 2020
169
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. *This snippet will add booked ticket on templates/my-bookings.php
  3. */
  4. <?php do_action('em_template_my_bookings_header'); ?>
  5. <?php
  6. global $wpdb, $current_user, $EM_Notices, $EM_Person;
  7. if( is_user_logged_in() ):
  8. $EM_Person = new EM_Person( get_current_user_id() );
  9. $EM_Bookings = $EM_Person->get_bookings();
  10. $bookings_count = count($EM_Bookings->bookings);
  11. if($bookings_count > 0){
  12. //Get events here in one query to speed things up
  13. $event_ids = array();
  14. foreach($EM_Bookings as $EM_Booking){
  15. $event_ids[] = $EM_Booking->event_id;
  16. }
  17. }
  18. $limit = ( !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
  19. $page = ( !empty($_GET['pno']) ) ? $_GET['pno']:1;
  20. $offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
  21. echo $EM_Notices;
  22. ?>
  23. <div class='em-my-bookings'>
  24. <?php if ( $bookings_count >= $limit ) : ?>
  25. <div class='tablenav'>
  26. <?php
  27. if ( $bookings_count >= $limit ) {
  28. $link = em_add_get_params($_SERVER['REQUEST_URI'], array('pno'=>'%PAGE%'), false); //don't html encode, so em_paginate does its thing
  29. $bookings_nav = em_paginate( $link, $bookings_count, $limit, $page);
  30. echo $bookings_nav;
  31. }
  32. ?>
  33. <div class="clear"></div>
  34. </div>
  35. <?php endif; ?>
  36. <div class="clear"></div>
  37. <?php if( $bookings_count > 0 ): ?>
  38. <div class='table-wrap'>
  39. <table id='dbem-bookings-table' class='widefat post fixed'>
  40. <thead>
  41. <tr>
  42. <th class='manage-column' scope='col'><?php _e('Event', 'events-manager'); ?></th>
  43. <th class='manage-column' scope='col'><?php _e('Date', 'events-manager'); ?></th>
  44. <th class='manage-column' scope='col'><?php _e('Spaces', 'events-manager'); ?></th>
  45. <th class='manage-column' scope='col'><?php _e('Status', 'events-manager'); ?></th>
  46. <th class='manage-column' scope='col'><?php _e('Bookings', 'events-manager'); ?></th>
  47. <th class='manage-column' scope='col'>&nbsp;</th>
  48. </tr>
  49. </thead>
  50. <tbody>
  51. <?php
  52. $rowno = 0;
  53. $event_count = 0;
  54. $nonce = wp_create_nonce('booking_cancel');
  55. foreach ($EM_Bookings as $EM_Booking) {
  56. /* @var $EM_Booking EM_Booking */
  57. $EM_Event = $EM_Booking->get_event();
  58. if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
  59. $rowno++;
  60. ?>
  61. <tr>
  62. <td><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
  63. <td><?php echo $EM_Event->start()->i18n( get_option('dbem_date_format') ); ?></td>
  64. <td><?php echo $EM_Booking->get_spaces() ?></td>
  65. <td>
  66. <?php echo $EM_Booking->get_status(); ?>
  67. </td>
  68. <td>
  69. <?php
  70. $EM_Tickets_Bookings = $EM_Booking->get_tickets_bookings();
  71. $val = "";
  72. foreach( $EM_Tickets_Bookings->tickets_bookings as $EM_Ticket_Booking ){
  73. $val .= "<small>Ticket Name:" . $EM_Ticket_Booking->get_ticket()->ticket_name . "</small> <br>";
  74. $val .= "<small>Ticket Amount:" . $EM_Ticket_Booking->get_ticket()->get_price_with_tax(true) ."</small> <br><br>";
  75. }
  76. echo $val;
  77. ?>
  78. </td>
  79. <td>
  80. <?php
  81. $cancel_link = '';
  82. if( !in_array($EM_Booking->booking_status, array(2,3)) && get_option('dbem_bookings_user_cancellation') && $EM_Event->get_bookings()->has_open_time() ){
  83. $cancel_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_cancel', 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$nonce));
  84. $cancel_link = '<a class="em-bookings-cancel" href="'.$cancel_url.'" onclick="if( !confirm(EM.booking_warning_cancel) ){ return false; }">'.__('Cancel','events-manager').'</a>';
  85. }
  86. echo apply_filters('em_my_bookings_booking_actions', $cancel_link, $EM_Booking);
  87. ?>
  88. </td>
  89.  
  90. </tr>
  91. <?php
  92. }
  93. do_action('em_my_bookings_booking_loop',$EM_Booking);
  94. $event_count++;
  95. }
  96. ?>
  97. </tbody>
  98. </table>
  99. </div>
  100. <?php else: ?>
  101. <?php _e('You do not have any bookings.', 'events-manager'); ?>
  102. <?php endif; ?>
  103. <?php if( !empty($bookings_nav) && $bookings_count >= $limit ) : ?>
  104. <div class='tablenav'>
  105. <?php echo $bookings_nav; ?>
  106. <div class="clear"></div>
  107. </div>
  108. <?php endif; ?>
  109. </div>
  110. <?php do_action('em_template_my_bookings_footer', $EM_Bookings); ?>
  111. <?php else: ?>
  112. <p><?php echo sprintf(__('Please <a href="%s">Log In</a> to view your bookings.','events-manager'),site_url('wp-login.php?redirect_to=' . urlencode(get_permalink()), 'login'))?></p>
  113. <?php endif; ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×