Hi,
Is it possible to get the information on the booking form to save under the users WordPress profile as well as on the booking?
Example: if a user enters an address or phone number then it is stored and reusable.
Please let me know whether this can be done.
Cheers.

Alex Steer
Hi Alex,
There are no UI settings to do this, but it’s possible to implement.
You can copy the from data into user meta as follows. Please note that you’d probably want to skip certain fields (hidden
, for example) or only target fields with specific IDs.
add_action( 'eventorganiser_booking_form_saved', 'my_form_saved_callback' );
function my_form_saved_callback( $form, $booking_id ){
$bookee_id = (int) eo_get_booking_meta( $booking_id, 'bookee' );
if( $bookee_id <= 0 ){
return;
}
$elements = $form->flatten_elements();
foreach( $elements as $element ){
//skip types
$skip = array(
'ticketpicker', 'antispam', 'section', 'html', 'discount-code',
'fieldset', 'hook', 'hidden',
);
if ( in_array( $element->type, $skip ) ){
continue;
}
$value = $element->get_value();
if( !is_null( $value ) ){
$key = 'my_prefix' . $form->id . '_' . $element->id;
update_user_meta( $bookee_id, $key, $value );
}
}
}
I won’t go into my detail, but you can use the normal WordPress user admin hooks to display this data. You can also ‘pre-fill’ the form by using the eventorganiser_get_event_booking_form
hook.
The difficulty is in ensuring that only ‘appropriate’ data is copied as user meta data (i.e. data that it makes sense to). Custom fields added by the plug-in have no meaning to the plug-in, so it can’t automatically identify which fields hold data associated to the user. How best to handle this usually depends on context.

Stephen Harris
Stephen,
Thanks for your reply.
I am assuming I would put the above in my functions file, correct?
Do you have an example of the code where I am targeting the specific fields I want to capture, rather than excluding the ones I don’t?
This might be a nice feature to add in the UI, maybe a check box on some of the field types like address for instance would work nicely.
I couldn’t see ‘eventorganiser_get_event_booking_form’ in your codex can you point me in the right direction?
Many thanks.

Alex Steer
Hi Alex,
Do you have an example of the code where I am targeting the specific fields I want to capture, rather than excluding the ones I don’t?
Do you mean, by ID, for example? If so
$whitelist_ids = array( 5, 8, 12 ); //Array of field IDs to sore
if( !in_array( $element->id, $whitelist_ids ) ){
continue;
}
It’s not yet documented, but all you need to know is that it fires when retrieving a booking form for a particular event, and passes the booking form object and event ID:
add_action ('eventorganiser_get_event_booking_form', 'my_get_event_booking_form_callback', 10, 2 );
function my_get_event_booking_form_callback( $form, $event_id ){
foreach( $elements as $element ){
//skip elements as required
//set $value based on user meta
$element->set_value( $value );
}
}

Stephen Harris