• Resolved costino80

    (@costino80)


    Hello,

    Is it possible to force delete the event from EM_Booking Object when a booking is cancelled ? On “my booking page”, when a user cancels an event, the booking count stays the same $bookings_count = count($EM_Bookings->bookings);

    As it never goes back to 0, when a user has no event booked (all cancelled), the condition if( $bookings_count = 0) is not met and the message “You do not have any bookings.” isn’t shown…

    Any suggestion ?
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,
    You can check available bookings with below condition.
    get_bookings($ids_only = false, $status= false) function accepts these parameters.
    You can check this at wp-content/plugins/events-manager/classes/em-person.php at line 33.
    Booking status are as below.
    `0 => __(‘Pending’,’events-manager’),
    1 => __(‘Approved’,’events-manager’),
    2 => __(‘Rejected’,’events-manager’),
    3 => __(‘Cancelled’,’events-manager’),
    4 => __(‘Awaiting Online Payment’,’events-manager’),
    5 => __(‘Awaiting Payment’,’events-manager’)`
    you can try,

    $EM_Bookings = $EM_Person->get_bookings(false, [0,1]);
    $bookings_count = count($EM_Bookings->bookings);
    • This reply was modified 3 years, 9 months ago by chathuripxl.
    • This reply was modified 3 years, 9 months ago by chathuripxl.
    Thread Starter costino80

    (@costino80)

    Hello,

    Thanks but it doesn’t work.
    It’s like the $bookings_count, the available bookings doesn’t “go down” when the user cancels an event…

    Here is my full code :

    <?php do_action('em_template_my_bookings_header'); ?>
    <?php
    	global $wpdb, $current_user, $EM_Notices, $EM_Person;
    	if( is_user_logged_in() ):
    		$EM_Person = new EM_Person( get_current_user_id() );
    		$EM_Bookings = $EM_Person->get_bookings();
    		$bookings_count = count($EM_Bookings->bookings);
    		if($bookings_count > 0){
    			//Get events here in one query to speed things up
    			$event_ids = array();
    			foreach($EM_Bookings as $EM_Booking){
    				$event_ids[] = $EM_Booking->event_id;
    			}
    		}
    		$limit = ( !empty($_GET['limit']) ) ? $_GET['limit'] : 20;//Default limit
    		$page = ( !empty($_GET['pno']) ) ? $_GET['pno']:1;
    		$offset = ( $page > 1 ) ? ($page-1)*$limit : 0;
    		echo $EM_Notices;
    		?>
    				<?php if( $bookings_count > 0):
    						
    						$rowno = 0;
    						$event_count = 0;
    						$nonce = wp_create_nonce('booking_cancel');
    						foreach ($EM_Bookings as $EM_Booking) {
                                
    						     /* @var $EM_Booking EM_Booking */
    							$EM_Event = $EM_Booking->get_event();
    							if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
    								$rowno++;
    								// Filter out already cancelled bookings.
                                if( 3 != $EM_Booking->booking_status ) {
    								?>
                                    <div class='myevent-container'>
    								<div class="event">
                                    <div class="event-date">
                                    <?php echo $EM_Event->start()->i18n( get_option('dbem_date_format') ); ?>
                                    </div>
                                    <div class="event-title">
    								<h3><?php echo $EM_Event->output("#_EVENTLINK"); ?></h3>
                                    </div>
                                    </div>
    								<div class="event-places">
    								<p><?php echo $EM_Booking->get_spaces() ?></p>
    								</div>
    								<div class="event-status">
    								<?php echo $EM_Booking->get_status(); ?>
    								</div>
    								<div class="booking">
    										<?php
    										$cancel_link = '';
    										if( !in_array($EM_Booking->booking_status, array(2,3)) && get_option('dbem_bookings_user_cancellation') && $EM_Event->get_bookings()->has_open_time() ){
    											$cancel_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_cancel', 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$nonce));
    											$cancel_link = '<a class="em-bookings-cancel" href="'.$cancel_url.'" onclick="if( !confirm(EM.booking_warning_cancel) ){ return false; }">'.__('Cancel','events-manager').'</a>';
    										}
    										echo apply_filters('em_my_bookings_booking_actions', $cancel_link, $EM_Booking);
    										?>
    								</div>
                                    </div>						
    								<?php
                                }
    							}
    							do_action('em_my_bookings_booking_loop',$EM_Booking);
    							$event_count++;
    						}
    						?>
    				<?php else: ?>
    					<?php _e('You do not have any bookings.', 'events-manager'); ?>
    				<?php endif; ?>
    		<?php do_action('em_template_my_bookings_footer', $EM_Bookings); ?>
    <?php else: ?>
    	<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>
    <?php endif; ?>

    I never reach php _e('You do not have any bookings.', 'events-manager')

    because

    if( $bookings_count > 0) is never 0 after the user has booked and cancelled an event…

    Another suggestion maybe ?

    • This reply was modified 3 years, 9 months ago by costino80.
    • This reply was modified 3 years, 9 months ago by costino80.
    • This reply was modified 3 years, 9 months ago by costino80.
    • This reply was modified 3 years, 9 months ago by costino80.
    Thread Starter costino80

    (@costino80)

    Hello @chathuripxl ,

    I don’t know why I didn’t see your last message before my last reply, but it works like a charm now ! THANK YOU !

    For others, the code below limits the query to show only pending and approved events of a user. When the user cancels an event, the event disappears from the list.

    $EM_Bookings = $EM_Person->get_bookings(false, [0,1]);

    @chathuripxl is there a page where I can see the most common functions of EM and the parameters they accept ?

    Again, thank you !

    Hello,
    It is great to hear that it is working. Sorry and as far as I know there is no such page like list down all common functions.
    Thanks

    Thread Starter costino80

    (@costino80)

    Ok.

    The documentation on Event Manager website is very straightforward and complete but @angelo_nwl that would be great to have another page with the main functions and other useful stuffs like hooks, etc…

    Maybe later ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Delete the event from EM_Booking Object when booking cancelled ?’ is closed to new replies.