Attendee limit on registration

Attendee limit on registration addon
This tutorial shows how to attendee limit on registration addon. First add a new field in functions.php and following tutorial Adding a new field for event submission form documentation. If you want to add field using field editor make lable name registration limit. Once you have added fields you can add below code to your function.php file.
 
Open up your theme functions.php field and create a function to the events section. First, hook it in:
add_filter('event_manager_registration_addon_form','custom_event_registration_form_addon',100);
Then write the function:
/**
* @return boolean 
*/
function custom_event_registration_form_addon(){
$event_id = get_the_ID();
$args = apply_filters( 'event_manager_custom_event_registrations_args', array(
'post_type' => 'event_registration',
'post_status' => array_diff( array_merge( array_keys( get_event_registration_statuses() ), array( 'publish' ) ), array( 'archived' ) ),
'ignore_sticky_posts' => 1,
'posts_per_page' => '-1',
'post_parent' => $event_id
) );

$the_query = new WP_Query( $args );
//change the 5 to your limitation of attendee
$registration_limit = get_post_meta($event_id,'_registration_limit',true);
//_registration_limit is a field name
if($registration_limit >= 0 && $the_query->found_posts >= $registration_limit ){
return false;
}
return true;
}