[AUTOMATIQUE] Cet article a plus de 5 ans.
Il se peut donc que les informations qu'il fournit ne soient plus totalement exactes.

If you have the free version of Events Manager which is available on WordPress.org, you don’t have the ability to add custom fields to the register form directly from the admin. This feature is only available for the PRO version of the plugin, but you can easily do it with some hooks! You have to paste the above functions in your theme functions.php file.

For this purpose, we need 4 hooks ; 2 actions and 2 filters.

 

The functions

  • First action hooks the form template to add the additional field. In this example, it is the company name.
  • The second hook is a filter which save the form input value in the database.
  • The third one add the new field to the list of available fields in the admin (when you choose which one to display in the listing view).
  • And the last filter add the field to the table when it is activated in the view (this hook is also used when you export data).
function bweb_add_custom_event_fields(){
	?>
		<p>
			<label for='user_company'><?php esc_html_e('Company', 'textdomain'); ?></label>
			<input type="text" name="user_company" id="user-company"  class="input" value="<?php if(!empty($_REQUEST['user_company'])) echo esc_attr($_REQUEST['user_company']); ?>" />
		</p>

	<?php
}
add_action('em_register_form','bweb_add_custom_event_fields');


function  bweb_save_custom_event_fields (){
	global $EM_Booking ;
	if( ! empty( $_REQUEST['user_company'] ) ){
			$EM_Booking->booking_meta['registration']['user_company'] = wp_kses( $_REQUEST['user_company'], array() );
	}
}
add_filter('em_booking_add','bweb_save_custom_event_fields');	


function bweb_table_custom_event_fields($template, $EM_Bookings_Table){
        $template['user_company'] = __('Company', 'textdomain');
        return $template;
}
add_action('em_bookings_table_cols_template', 'bweb_table_custom_event_fields',10,2);
 
 
function bweb_display_col_custom_event_fields($val, $col, $EM_Booking, $EM_Bookings_Table, $csv){
        if( $col == 'user_company' ){
                $val = $EM_Booking->get_person()->user_company;               
        }
        return $val;
}
add_filter('em_bookings_table_rows_col','bweb_display_col_custom_event_fields', 10, 5);

 

As always, you just have to paste these functions in your theme dedicated file, then change the user_company string to what you want.

Sorry, the screenshot is in french
Sorry, the screenshot is in french

After saving everything, you have to open the parameter popup windows and drag & drop the new field on the left of the box to activate it in the table view and in the CSV export.

Voilà! We’re done!

Post written byBrice CAPOBIANCO

WordPress addict and self-taught. I love to learn and to create, then to share…
Founder of bweb.
Share this post

Your email address will not be published. Required fields are marked *

Show 27 comments

27 comments

  1. This is very helpful, thanks! Is there a way to remove the comment field? And perhaps change the Name field into a First and Last field?

  2. Thanks for sharing such great information with us. This information is use full for us. I hope you will share more valuably information about the Events Manager for WordPress.

  3. Hy,
    I have put this extra Field with the two steps you wrote in your articles.
    Is it possible to show this data in the booking emails like #_EVENTNAME

    ??

  4. First of all, thank you very much for that code.
    I’ve added everything to my functions.php except for the bweb_save_custom_event_fields() function that I’ve placed in the /placeholders/bookingform.php as there is the booking submit button placed. I would like to store the input of the fields as soon as this button gets clicked.
    In the functions.php I’ve defined several fields like:
    user_motorcycle
    user_experience
    user_title
    user_firstname
    user_lastname
    user_email
    etc.

    Interestingly, the fields user_firstname, user_lastname and user_email got stored as supposed.
    The other fields are all empty.

    Any idea what the root cause could be?

  5. Hi Brice, I tried to put the content in my child theme functions.php files,
    but it does not work … I did not understand how to drag from the left and what, when you say: “After saving everything, you have to open the parameter popup windows and drag & drop the new field on the left of the box to activate it in the table view and in the CSV export.”
    Can you tell me how? Thank you very much

  6. Hi guys,

    I thought that i can share with you which i am currently using plugin for event listing.

    For adding any field not matter from backend side or frontend side, try WP Event Manager, (www.wp-eventmanager.com)

    I am sure that you people will like it bcz it is free with more features.

    Thanks

  7. Beautiful solution, works great, also for multiple fields. However, I have one question. How do I get the “Change personal details” applet in the admin view of a booking to show and edit the new fields? Now, it displays a photo of the user, his or her name, email and phone. I would like to show up the new fields as well?

    • Hi Rudy,
      I’m sorry but I haven’t worked with this plugin for a while and I don’t use it anymore on any of my project so I can’t answer you.
      Hope you’ll figure out how to achieve what you need.
      Best,

  8. Hi

    Now is possible to ad custom attributes in settings/formatting/single event page format also in free version, but I need to style front-end input form and add some custom text (fill in instruction) for each custom attributes (only visible in event input form but not visible in published event?
    Do you know where any hove i can do this?

    Thx, BR
    MM

  9. Thanks for this article.

    I was able to create some new additional fields in the booking form. I created a textarea and also a select field.
    Everything works, thanks for your tutorial.

    • Hi Mo,
      I have been trying to add more than one additional field and would like to know how you did it if you have the time.
      Thank you.

    • You can try this hook ’em_booking_form_custom’ instead of ’em_register_form’. Maybe it will help you.

  10. Hi Brice.

    I put your code into my theme function.php.
    In admin area I drag&drop a new created field “Company” into table and this works.

    But I can not see this new created field in my Booking form page.
    Can you please advise me? Thanks

    • Hi Kypo,
      I’m sorry but I don’t know why, this is still working for me on my side.
      Did you get any PHP warnings or errors ?

  11. where is it

    After saving everything, you have to open the parameter popup windows and drag & drop the new field on the left of the box to activate it in the table view and in the CSV export.

    how can i do that

  12. Wanted to know how to add custom Select field instead of text field, Like Dropdown for countries, How to do that? Please

  13. hi Brice
    thank for your kindly help , i have tried your method and setting but the booking table still havnt any new input data showing in the field,dont know why ?

    paul

  14. Dear Brice
    thank for your kindly help , i have tried to add the function to theme function.php , the new booking field have shown up succeeful, however , i cannot view the data or record in CSV or booking table ,i am not sure the data is saved in the database , would you tell me why ? thank so much

    best regards
    paul

    • Hi Paul,
      I’ve just added a screenshot to the end of the above article, it maybe can solve your issue.
      Cheers

  15. would you mind tell me more where this function put in , would you mind mind give me file name ,e.g booking-fields.php?

    • Hi Paul,
      You have to put this functions in your child-theme functions.php file.
      You should never edit plugin’s or core’s files!
      Cheers 😉

  16. Hi Brice,

    I’ve searched around and thought editing the corresponding code in em-person.php (yourtheme/plugins/classes/) would work but it doesn’t.

    Thanks for your quick response anyway.

    cheers

  17. Hello Brice,

    Just want to say you really save my day for your awesome post! None of the solutions I searched can compare to your simple and straight to the point answer. Thanks a lot!

    How could we also display the additional field in the “Personal Details” table in admin area?

    Best regards,
    Stan

    • Hi Stan,
      Unfortunately, I don’t have Events Manager installed anymore. So I can’t further help.
      Sorry 😉
      Cheers