Filter eo_get_user_booking_history by category

WordPress Event Management, Calendars & Registration Forums General Question Filter eo_get_user_booking_history by category

This topic contains 5 replies, has 2 voices, and was last updated by  Jon Packman 10 years, 5 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #8301

    Is there a way to get a user’s bookings in a specific category of event using the eo_get_user_booking_history function? Or if not, is there another way to do it?

    Thanks in advance.

    Jon Packman
    #8304

    Hi Jon,

    There’s no direct way of doing this,

    eo_get_user_booking_history() is just a wrapper for eo_get_bookings(), specifically:

    eo_get_bookings( array(
        'bookee_id' => $user_id
    ));

    That, itself, is a wrapper for a WP_Query and the (post) ID of the event associated with a booking is stored in _eo_booking_event_id. So you could try the following:

    $user_id = get_current_user_id();
    
    //Get an array of event (post) IDs in a specific category
    $event_ids = eo_get_events( array(
        'group_events_by' => 'series',
        'fields' => 'ids',
        'event-category' => 'my-cat-slug'
    ) );
    
    //Get bookings whose event ID is in that array
    eo_get_bookings( array(
        'bookee_id' => $user_id,
        'meta_query' => array(
             array(
                  'key' => '_eo_booking_event_id',
                  'value' => $event_ids,
                  'compare' => 'IN'
             )
        ),
    ));

    Please note that if $event_ids is an empty array, then all bookings (for that user) would be returned. This is the default behaviour of meta_query when ‘compare’ is ‘IN’ and the value is an empty array.

    Hope that helps,

    Stephen Harris
    #8308

    Thanks Stephen, that worked perfectly. I didn’t need get_current_user_id as I’m adding these bookings as extra profile fields, so user_id on its own does the job.

    Jon Packman
    #8329

    Final (I hope!) question on the same subject – how would I get the date of the event instead of the date the event was booked (replacing eo_get_booking_date below)?

    foreach( $bookings as $booking ){
               printf(
                       '
  • You booked %1$d tickets for %2$s on %3$s
  • ', eo_get_booking_meta( $booking->ID, 'ticket_quantity' ), 'ID, 'event_id' ) ).'">'.get_the_title( eo_get_booking_meta( $booking->ID, 'event_id' ) ).'', eo_get_booking_date( $booking->ID, 'jS F Y' ) ); }
    Jon Packman
    #8337

    You can get the event ID and occurrence ID as follows,

         $event_id = eo_get_booking_meta( $booking->ID, 'event_id' );
         $occurrence_id = eo_get_booking_meta( $booking->ID, 'occurrence_id' );

    and then use eo_get_the_start(). If you are ‘booking by series’ then the occurrence ID will always be 0.

    foreach( $bookings as $booking ){
         $event_id = eo_get_booking_meta( $booking->ID, 'event_id' );
         $occurrence_id = eo_get_booking_meta( $booking->ID, 'occurrence_id' );
         printf(
                'You booked %1$d tickets for %2$s on %3$s',
                 eo_get_booking_meta( $booking->ID, 'ticket_quantity' ),
                 get_the_title( $event_id ),
                 eo_get_the_start( 'jS F Y', $event_id, null, $occurrence_id );
         );
    }

    See codex on eo_get_booking_meta() and eo_get_the_start() for details / examples

    Stephen Harris
    #8366

    Great, thanks Stephen.

    Jon Packman
Viewing 6 posts - 1 through 6 (of 6 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.