Hi @makmerghen
Please try this code snippet:
// Add current logged-in user as a referer
add_action( 'um_registration_complete', 'um_110821_user_referral' ,1 );
function um_110821_user_referral( $user_id ){
$referer_id = get_current_user_id();
update_user_meta( $user_id, "um_user_referral", $referer_id );
}
// Validate registration limit
add_action("um_submit_form_register","um_110821_validate_registration_limit", 1 );
function um_110821_validate_registration_limit( $post_form ){
//if( isset( $post_form['user_email'] ) && ! empty( $post_form['user_email'] ) ){
$users = count( get_users(
array(
'meta_key' => "um_user_referral",
'meta_value' => get_current_user_id(),
"fields" => "ids"
)
)
);
if( UM()->form()->errors['user_email'] === "You must provide your email" ){
unset( UM()->form()->errors['user_email'] );
}
if( "membership30" == um_user("role") ){
if( $users > 30 ){
UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) );
}
}elseif( "membership50" == um_user("role") ){
if( $users > 50 ){
UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) );
}
}elseif( "membership100" == um_user("role") ){
if( $users > 100 ){
UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) );
}
}elseif( "administrator" == um_user("role") ){
UM()->form()->add_error('user_email', __( 'You are not allowed to add more users', 'ultimate-member' ) );
}else{
// no limit
}
//}
if( empty( UM()->form()->errors ) ){
unset( UM()->form()->errors );
}
}
I’ve combined the control registration number
and create email if no email in UM register form to avoid error
.
Regards,