WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] How to manually save Booking (4 posts)

  1. estepix
    Member
    Posted 1 year ago #

    Hi I just read this thread:
    http://wordpress.org/support/topic/plugin-events-manager-save-booking?replies=3

    And I need to do exactly that, @Marcus your recommendation was:
    you need to also create a EM_Ticket_Booking object to associate the booking with a ticket for x spaces of that booking

    Could you explain further on how to do that?
    Many thanks

    http://wordpress.org/extend/plugins/events-manager/

  2. agelonwl
    Member
    Posted 1 year ago #

    hi,

    I think it's something like this

    $tickets_bookings_result = $EM_Booking->get_tickets_bookings()->save();
    //catch error
    if ( !$tickets_bookings_result  ){
    
    }
  3. estepix
    Member
    Posted 1 year ago #

    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.

  4. agelonwl
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic