Support » Plugin: Events Manager » How to manually save Booking

Viewing 3 replies - 1 through 3 (of 3 total)
  • hi,

    I think it’s something like this

    $tickets_bookings_result = $EM_Booking->get_tickets_bookings()->save();
    //catch error
    if ( !$tickets_bookings_result  ){
    
    }

    Thanks agelonwl, I found a solution which seems to be working fine for me:

    $EM_Person = new EM_Person($user_id);
    $EM_Event = new EM_Event($event_id);
    $EM_Tickets = $EM_Event->get_tickets();
    $EM_Booking = new EM_Booking();
    $EM_Tickets_Bookings = new EM_Tickets_Bookings($EM_Booking);
    
    $EM_Booking->event_id = $event_id;
    $EM_Booking->person_id = $user_id;
    $EM_Booking->booking_price = "0.00";
    $EM_Booking->booking_spaces = "1";
    $EM_Booking->booking_status = "0";
    $EM_Booking->person = $EM_Person;
    foreach ($EM_Tickets->tickets as $key => $EM_Ticket) {
        $EM_Ticket_Booking = new EM_Ticket_Booking();
        $EM_Ticket_Booking->ticket_id = $EM_Ticket->ticket_id;
        $EM_Ticket_Booking->ticket_booking_spaces = $EM_Booking->booking_spaces;
        $EM_Ticket_Booking->save();
        $EM_Tickets_Bookings->tickets_bookings[$key] = $EM_Ticket_Booking;
    }
    
    $EM_Booking->tickets_bookings = $EM_Tickets_Bookings;
    $EM_Booking->save();

    Maybe it’s too much code just to save a booking, but in this way I’m making sure the $EM_Booking object has all the data required to be saved properly.

    that seems to worked however maybe you can check this lines (for reference only) at events-manager/em-actions.php at around line 283 – 309

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to manually save Booking’ is closed to new replies.