Cap bookings per user

This topic contains 2 replies, has 2 voices, and was last updated by  Jody Brown 9 years, 9 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #11773

    Hi Stephen

    I want to cap users to be only able tp purchase 2x tickets for each event.

    I have played with the bookings and found I can cap the amount of tickets total and per ticket type but not for user.

    Is this possible ? My tickets are only available to users that are logged in.

    Thanks

    Jody

    Jody Brown
    #11775

    Hi Jody,

    There’s an tutorial on how to limit bookings to one ticket per user, which can be adapted to allow two tickets. (For just check if a user has made a prior booking you can use the function eo_user_has_bookings() (see codex).

    For checking if the number of tickets purchased exceeds 2, it is slightly more involed:

    //1. Get relevant bookings associated with the user
    //You'll need to provide the $event_id (and $occurrence_id) if applicable. and provide the statuses to check
    $bookings = eo_get_bookings( array( 
        'bookee_id' => get_current_user_id(),
        'event_id' => $event_id, 
        'occurrence_id' => $occurrence_id, //Remove if not selling by date
         'status'=> $status, //"any" for any status. Or array( 'confirmed', 'other-custom-status' ),
        'fields'=>'ids'
    ) );
    
    //2. Count the tickets in these bookings
    $ticket_count = 0;
    if( $bookings ){
          foreach( $booking as $booking_id ){
                $ticket_count += eo_get_booking_meta( $booking_id, 'ticket_quantity' );
          }
    }
    
    //You can then check $ticket_count.

    **Please note the above is untested*

    Stephen Harris
    #11776

    Great thanks again Stephen

    They have just changed the plan on me and only want one per user

    So i used the link you shared and made a plugin works perfect thanks 🙂

    Jody Brown
Viewing 3 posts - 1 through 3 (of 3 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.