Limiting number of tickets in a booking shows no error message

WordPress Event Management, Calendars & Registration Forums Report A Bug Limiting number of tickets in a booking shows no error message

This topic contains 2 replies, has 2 voices, and was last updated by  Marco 4 years, 2 months ago.

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

    Hi,

    I want to limit the number of tickets in a booking according your tutorial in https://wp-event-organiser.com/blog/tutorial/limit-bookings-to-one-ticket/ (snippet copied to the site-utility.php).

    My test user already has a booking, and when he tries to book an additional ticket for the course, I would actually have expected an error message, e.g. near the submit button, as with other error messages.

    The message is mentioned in your article and defined in the code snippet (‘previous_booking’).
    But there isn’t one… Neither above the button, nor anywhere else in the booking form.

    Could you please check this. Has anything changed since 2013 that prevents the message from being displayed?

    Thanks,
    Marco

    Marco
    #38583

    Hi Marco,

    Yes there has been changes which I think has broken that code snippet slightly.

    Rather than use $errors->add you should retrieve an element from the booking form an attach errors to it.

    E.g. the line(s) in question should read:

    /* 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, eo_get_reserved_booking_statuses() ) ){
        //This error will prevent the booking from being processed, and display the given error message
        $form->get_element( 'ticketpicker' )->add_error( 'previous_booking', 'You have already made a booking for this event.' );
    }
    

    That should cause the error message to appear under the ticket picker.

    And further down you’d want to do:

    /* Throw error if booking contains multiple tickets */
    if( $total_qty > 1 ){
         $form->get_element( 'ticketpicker' )->add_error( 'too_many_tickets', 'You can only purchase one ticket.' );
    }
    
    Stephen Harris
    #38610

    Thanks, Stephen, it works now!

    Marco
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.