Hi Stephen,
Hope things are well – we’re getting close(ish) to our go-live on this large(ish) project.
I’d like to hook into when a booking has been made so that I can make a call to MailChimp’s API if the user has selected that he/she would like to subscribe to a mailing list.
Is the best place to do this the eventorganiser_pre_gateway_booking
hook? It doesn’t look to be documented, but digging through the source, it seems like the most likely candidate.
Cheers,
Andrew

Andrew Shankie
Hi Andrew,
That hook would do: it is triggered immediately before the user is taken to the payment gateway.
But if there were a (hypothetical) situation where a booking might be created without redirecting the user (e.g. suppose admins were allowed to add bookings from the dashboard, or an app create bookings from a phone), then you might miss it.
A better hook might be eventorganiser_new_booking
: this is triggered when booking is made.
However, these hooks fire before the event is confirmed. If that’s important then you should use eventorganiser_transition_booking_status
: this is triggered whenever a booking changes status. (Default statues are ‘pending’, ‘confirmed’ and ‘cancelled’, with a dummy ‘new’ status when the booking is first created).
add_action( 'eventorganiser_transition_booking_status', 'my_booking_status_transition' , 10, 3 );
function my_booking_status_transition( $new_status, $old_status, $booking ) {
if ( $new_status == 'confirmed' && $new_status != $old_status ) {
//booking has gone from one status to 'confirmed'
}
}
That would allow you to capture a booking being cancelled / restored too

Stephen Harris
Hi Stephen,
That’s really useful information. In fact, the hook I suggested would probably be wrong as we’ll be using Stripe, so the user is never taken away to a different payment gateway.
As I’m not too fussed about whether it’s confirmed (as they’ve asked to subscribe one way or another), I think eventorganiser_new_booking
looks like the right one.
Am I right in thinking that these hooks are currently undocumented? No great shakes as they’re easy enough to find in the source, but might be something worth documenting – I’d think that the use case of “do something else in PHP with information that was submitted” is fairly common.
Cheers,
Andrew

Andrew Shankie
Hi Stephen,
A little follow-on question: as I mentioned in the previous post, I’m trying to do a little integration with Mailchimp.
Here’s how it’ll work: I’ve added a custom checkbox field onto the booking form (which is ticked by default). If it’s ticked, I’ll make a call to Mailchimp’s API to add the email address to a list.
Above, we agree that eventorganiser_new_booking
is probably the right hook – in the callback it gives params $booking_id
and $booking
. In the returned booking object, it does (buried within some form objects) look like it might include the status of whether my checkbox is checked, but it looks untidy and I’m sure there’s a better way of doing it.
My inclination is to use eo_get_booking_ticket_meta()
, but it doesn’t return anything when called with booking reference numbers.
Any ideas?
Thanks in advance as always.
Best wishes,
Andrew

Andrew Shankie
Hi Andrew,
Just to clear up an earlier point: eventorganiser_pre_gateway_booking
will fire even if the user is taken away from the page, it simply fires before the payment gateway is invoked to process the payment. It will also fire even if no payment is required. It is a reasonable hook to use, but it is very much tied to the context of placing a booking on the site.
Regarding your later post, you want to use eo_get_booking_meta()
and the meta key: meta_{element-id}
( http://codex.wp-event-organiser.com/function-eo_get_booking_meta.html).
The $booking
array will (may) contain a reference to the EO_Booking_Form
instance that initiated the booking. (Again, at present that is a fair assumption – but you just be aware that in the future this might not be the case). In any case, I’d recommend using the booking meta function.

Stephen Harris