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
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
Thanks, Stephen, it works now!
Marco