Table of Contents
Introduction:
The Events Manager plugin, available on WordPress.org, offers a range of features to manage events. While the free version provides many functionalities, adding custom fields to the registration form directly from the admin is exclusive to the PRO version. However, you can achieve this customization using hooks and functions in your theme’s functions.php
file.
Adding Custom Fields:
To integrate custom fields into the registration form, we utilize four hooks: two actions and two filters.
1. Action: Hooking the Form Template
The first action is responsible for attaching the form template and introducing the new field. In this example, we’ll add a “Company Name” field.
// Add your custom field HTML here
2. Filter: Saving Form Input
The second hook, a filter, ensures that the input value from the custom field is saved in the database.
function sr_save_custom_event_fields (){ global $EM_Booking ; // Get the custom field value from the form submission if( ! empty( $_REQUEST['user_company'] ) ){ $EM_Booking->booking_meta['registration']['user_company'] = wp_kses( $_REQUEST['user_company'], array() ); } } add_filter('em_booking_add','sr_save_custom_event_fields');Displaying Custom Field in Admin:
To display the new custom field in the admin interface, two additional hooks are used.
3. Action: Admin Field Display
The third hook adds the new field to the list of available fields in the admin, enabling you to choose which fields to display in the listing view.
function sr_table_custom_event_fields($template, $EM_Bookings_Table){ $template['user_company'] = __('Company', 'textdomain'); return $template; } add_action('em_bookings_table_cols_template', 'sr_table_custom_event_fields',10,2);4. Filter: Activating Custom Field in View
The fourth filter adds the custom field to the table when it’s activated in the view. This filter is also used when exporting data.
function sr_display_col_custom_event_fields($val, $col, $EM_Booking, $EM_Bookings_Table, $csv){ if( $col == 'user_company' ){ // Add custom field to the list of columns $val = $EM_Booking->get_person()->user_company; } return $val; } add_filter('em_bookings_table_rows_col','sr_display_col_custom_event_fields', 10, 5);Conclusion:
By strategically employing these hooks and functions in your theme’sfunctions.php
file, you can enhance the Events Manager plugin’s registration form with custom fields. While the free version may lack direct support for this feature, this method empowers you to tailor the registration form according to your needs.Support and Assistance:
Should you encounter any issues during the implementation of these custom fields, please don’t hesitate to leave a comment on this post. We’re here to help you overcome any challenges and make the most out of your customized Events Manager registration form.
4 comments
Hello.
HI @Mishaelanimi
Hi,
tried this code out but don’t find the new field anywhere.
Where do I find it exactly in the Event Manager Admin
thanks
Pete
Within the admin dashboard, when navigating to ‘All Users’, upon selecting a specific user for editing, this field will become visible.