Advertisement
eventsmanager

Custom Booking form

Jan 29th, 2015
1,566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. This template file will display the form fields first before the ticket table
  5.  
  6. - create these folders inside your theme directory: wp-content > themes > Your Theme > plugins > events-manager > placeholders
  7. - create new php file bookingform.php
  8. - edit bookingform.php and copy this snippet
  9.  
  10. */
  11.  
  12. /*
  13. * This is where the booking form is generated.
  14. * For non-advanced users, It's SERIOUSLY NOT recommended you edit this form directly if avoidable, as you can change booking form settings in various less obtrusive and upgrade-safe ways:
  15. * - check your booking form options panel in the Booking Options tab in your settings.
  16. * - use CSS or jQuery to change the look of your booking forms
  17. * - edit the files in the forms/bookingform folder individually instead of this file, to make it more upgrade-safe
  18. * - hook into WP action/filters below to modify/generate information
  19. * Again, even if you're an advanced user, consider NOT editing this form and using other methods instead.
  20. */
  21.  
  22. /* @var $EM_Event EM_Event */
  23. global $EM_Notices;
  24. //count tickets and available tickets
  25. $tickets_count = count($EM_Event->get_bookings()->get_tickets()->tickets);
  26. $available_tickets_count = count($EM_Event->get_bookings()->get_available_tickets());
  27. //decide whether user can book, event is open for bookings etc.
  28. $can_book = is_user_logged_in() || (get_option('dbem_bookings_anonymous') && !is_user_logged_in());
  29. $is_open = $EM_Event->get_bookings()->is_open(); //whether there are any available tickets right now
  30. $show_tickets = true;
  31. //if user is logged out, check for member tickets that might be available, since we should ask them to log in instead of saying 'bookings closed'
  32. if( !$is_open && !is_user_logged_in() && $EM_Event->get_bookings()->is_open(true) ){
  33. $is_open = true;
  34. $can_book = false;
  35. $show_tickets = get_option('dbem_bookings_tickets_show_unavailable') && get_option('dbem_bookings_tickets_show_member_tickets');
  36. }
  37. ?>
  38. <div id="em-booking" class="em-booking <?php if( get_option('dbem_css_rsvp') ) echo 'css-booking'; ?>">
  39. <?php
  40. // We are firstly checking if the user has already booked a ticket at this event, if so offer a link to view their bookings.
  41. $EM_Booking = $EM_Event->get_bookings()->has_booking();
  42. ?>
  43. <?php if( is_object($EM_Booking) && !get_option('dbem_bookings_double') ): //Double bookings not allowed ?>
  44. <p>
  45. <?php echo get_option('dbem_bookings_form_msg_attending'); ?>
  46. <a href="<?php echo em_get_my_bookings_url(); ?>"><?php echo get_option('dbem_bookings_form_msg_bookings_link'); ?></a>
  47. </p>
  48. <?php elseif( !$EM_Event->event_rsvp ): //bookings not enabled ?>
  49. <p><?php echo get_option('dbem_bookings_form_msg_disabled'); ?></p>
  50. <?php elseif( $EM_Event->get_bookings()->get_available_spaces() <= 0 ): ?>
  51. <p><?php echo get_option('dbem_bookings_form_msg_full'); ?></p>
  52. <?php elseif( !$is_open ): //event has started ?>
  53. <p><?php echo get_option('dbem_bookings_form_msg_closed'); ?></p>
  54. <?php else: ?>
  55. <?php echo $EM_Notices; ?>
  56. <?php if( $tickets_count > 0) : ?>
  57. <?php //Tickets exist, so we show a booking form. ?>
  58. <form class="em-booking-form" name='booking-form' method='post' action='<?php echo apply_filters('em_booking_form_action_url',''); ?>#em-booking'>
  59. <input type='hidden' name='action' value='booking_add'/>
  60. <input type='hidden' name='event_id' value='<?php echo $EM_Event->event_id; ?>'/>
  61. <input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('booking_add'); ?>'/>
  62.  
  63. <?php if( $can_book ): ?>
  64. <div class='em-booking-form-details'>
  65.  
  66. <div>
  67. <?php
  68. do_action('em_booking_form_before_user_details', $EM_Event);
  69. if( has_action('em_booking_form_custom') ){
  70. //Pro Custom Booking Form. You can create your own custom form by hooking into this action and setting the option above to true
  71. do_action('em_booking_form_custom', $EM_Event); //do not delete
  72. }else{
  73. //If you just want to modify booking form fields, you could do so here
  74. em_locate_template('forms/bookingform/booking-fields.php',true, array('EM_Event'=>$EM_Event));
  75. }
  76. do_action('em_booking_form_after_user_details', $EM_Event);
  77. ?>
  78. </div>
  79.  
  80. <?php do_action('em_booking_form_footer', $EM_Event); //do not delete ?>
  81. <div class="clear"></div>
  82. <br/><br/>
  83. <div>
  84. <?php
  85. if( $show_tickets && $available_tickets_count == 1 && !get_option('dbem_bookings_tickets_single_form') ){
  86. do_action('em_booking_form_before_tickets', $EM_Event); //do not delete
  87. //show single ticket form, only necessary to show to users able to book (or guests if enabled)
  88. $EM_Ticket = $EM_Event->get_bookings()->get_available_tickets()->get_first();
  89. em_locate_template('forms/bookingform/ticket-single.php',true, array('EM_Event'=>$EM_Event, 'EM_Ticket'=>$EM_Ticket));
  90. do_action('em_booking_form_after_tickets', $EM_Event); //do not delete
  91. }
  92. ?>
  93. </div>
  94. <div class="clear"></div>
  95.  
  96. </div>
  97. <?php else: ?>
  98. <p class="em-booking-form-details"><?php echo get_option('dbem_booking_feedback_log_in'); ?></p>
  99. <?php endif; ?>
  100. <div class="clear"></div>
  101. <div>
  102. <?php
  103. // Tickets Form
  104. if( $show_tickets && ($can_book || get_option('dbem_bookings_tickets_show_loggedout')) && ($tickets_count > 1 || get_option('dbem_bookings_tickets_single_form')) ){ //show if more than 1 ticket, or if in forced ticket list view mode
  105. do_action('em_booking_form_before_tickets', $EM_Event); //do not delete
  106. //Show multiple tickets form to user, or single ticket list if settings enable this
  107. //If logged out, can be allowed to see this in settings witout the register form
  108. em_locate_template('forms/bookingform/tickets-list.php',true, array('EM_Event'=>$EM_Event));
  109. do_action('em_booking_form_after_tickets', $EM_Event); //do not delete
  110. $show_tickets = false;
  111. }
  112. ?>
  113. </div>
  114. <div class="clear"></div>
  115. <?php if( $can_book ): ?>
  116. <div class="em-booking-buttons">
  117. <?php if( preg_match('/https?:\/\//',get_option('dbem_bookings_submit_button')) ): //Settings have an image url (we assume). Use it here as the button.?>
  118. <input type="image" src="<?php echo get_option('dbem_bookings_submit_button'); ?>" class="em-booking-submit" id="em-booking-submit" />
  119. <?php else: //Display normal submit button ?>
  120. <input type="submit" class="em-booking-submit" id="em-booking-submit" value="<?php echo esc_attr(get_option('dbem_bookings_submit_button')); ?>" />
  121. <?php endif; ?>
  122. </div>
  123.  
  124. <?php do_action('em_booking_form_footer_after_buttons', $EM_Event); //do not delete ?>
  125. <?php endif; ?>
  126.  
  127.  
  128. </form>
  129. <?php
  130. if( !is_user_logged_in() && get_option('dbem_bookings_login_form') ){
  131. //User is not logged in, show login form (enabled on settings page)
  132. em_locate_template('forms/bookingform/login.php',true, array('EM_Event'=>$EM_Event));
  133. }
  134. ?>
  135. <br class="clear" style="clear:left;" />
  136. <?php endif; ?>
  137. <?php endif; ?>
  138. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement