Changing the booking section?

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 9 years, 12 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #10772

    Hi,

    there are a few things particularly I’d like to change about my booking section (and you may want to consider this as a feature request as well, but I need to change these things ASAP so for now I just need to know how):

    • I would like to add a cancel booking button, given the user has already booked an event
    • I Would like only to show the Book button if the user has not booked the event

    I actually ended up answering the first thing myself, but am posting the answer for anyone else:

    • Look in event-organiser-pro/templates/eo-booking-form.php and near the bottom (div with class eo-booking-purchase-row) is where you want to add the check for if they are booked. I used the following (PHP) code:

               $bookings = eo_get_bookings(array( "status"=>"confirmed","event_id"=>get_the_ID() ));
    
                $attendees = array();
                foreach($attendees as $attendee):
                    $attendees[] = $attendee->post_author;
                endforeach; 
    
                if(in_array(get_current_user_id(),$attendees)):`

    //etc...

    But how do I create a booking cancellation button?

    • This topic was modified 9 years, 12 months ago by  Gabriel David. Reason: Formatting code
    Gabriel David
    #10774

    Hi David,

    Regarding your snippet, you may want to checkout eo_user_has_bookings(). (warning: unless you specify the booking status, it defaults to ‘all’ and includes cancelled bookings. It never counts deleted bookings).

    The user cancelling their booking will be possible in 1.7.0, by using [booking_history bookee_can_cancel=true]. This adds a column to the booking history table (shortcode) which allows the user to cancel their booking. It’s not quite, what you’re after, but it works. Otherwise a ‘cancel’ button could just be a link which your site listens for (e.g. www.yoursite.com?action=cancel_booking={booking_id}) and then cancels the bookings (you’ll want to perform some security checks, and nonce checks) and then redirects them back to the event.

    Regarding hiding the book button – currently the button is displayed in the eo-booking-form.php template. This will change in 1.8.0. The button is being moved ‘inside’ the booking form customiser. As such you’ll be able to remove it via the API for example:

    function my_remove_book_button( $form, $event_id ){
         //Only valid for 1.8.0
         $user_id   =  get_current_user_id();
         $event_id = $this->form->get( 'event_id' );
         $noncancelled_statuses = eo_get_booking_statuses( array( 'name' => 'cancelled' ), 'names', 'not' );
    
         //If user is logged in, and has previous (non-cancelled) bookings for this event
         if( $user_id && eo_user_has_bookings( $user_id, $event_id , 0, $noncancelled_statuses ) ){
              $element = $form->remove_element( 'submit' );
          }
    
    }
    add_action( 'eventorganiser_get_event_booking_form', 'my_remove_book_button', 10, 2 );
    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.