Limit maximum tickets per booking

This topic contains 2 replies, has 2 voices, and was last updated by  Andrew Shankie 9 years, 7 months ago.

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

    Hi Stephen,

    My client would like to limit a maximum number of tickets per booking (across all classes of tickets on an event and occurrence). For instance, if there was a Pixies gig on next week, they’d want to be able to stop a scalper from going and buying 100 tickets.

    This thread get close – but seems to be slightly more complex than my example.

    Any ideas how I might do this? Or should I get to work adapting your solution to Henning’s problem?

    Best wishes,

    Andrew

    Andrew Shankie
    #18048

    That thread indicates how to add a custom property to tickets. I don’t think that’s necessary here, as your limit on bookings is probably fixed and global.

    I think this tutorial gets you most of the way: http://wp-event-organiser.com/blog/tutorial/limit-bookings-to-one-ticket/ (changing 1 to 100).

    The problem here is that that tutorial will prevent a second booking for the same event/occurrence. In this case, if someone made a booking of 50, then you’d be happy to let them make a second booking of up to 49.

    To do that, you’d want to replace the following in the tutorial:

    /* Throw error if user has previously made a booking for this event */
    if( eo_user_has_bookings( get_current_user_id(),  $post_id, $occurrence_id ) ){
        //This error will prevent the booking from being processed, and display the given error message
        $errors->add( 'previous_booking', 'You have already made a booking for this event.' );
    }
    

    with something a bit more complex:

    $previous_bookings = eo_get_bookings( array( 
         'bookee_id'     => get_current_user_id(), 
         'event_id'      => $event_id, 
         'occurrence_id' => $occurrence_id, 
         'status'        => 'any', 
         'fields'        => 'ids' 
     ));
    
    $previous_tickets = 0;
    if( $prevous_bookings ){
           foreach( $previous_bookings as $p_booking_id ) {
                  $previous_tickets += eo_get_booking_meta( $p_booking_id, 'ticket_quantity' );
           }
    }
    
     $total_qty = array_sum( $tickets )
    
     if( $total_qty + $previous_tickets > 100 ){
        $errors->add( 'previous_booking', 'You have already made a booking for this event.' );
     }
    

    This code is untested, but it should at least get you most of the way there.

    Stephen Harris
    #18052

    Hi Stephen,

    That’s great. Thanks ever so much. I’ll drop it in and let you know if I run into any troubles.

    Cheers,

    Andrew

    Andrew Shankie
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.