Please edit your function and add code used below for adding user role in functions.php
This is basic idea how roles can be added and removed and how you can check your filed values. Please use according to your requirements.
add_action( 'profile_update', 'my_profile_update', 10, 2 );
function my_profile_update( $user_id, $old_user_data ) {
// here you need to update your required conditions, ie: check if meta values are set or not. I haven't checked your meta values but its supposed to like condition which is written in if condition, otherwise thr role update will work but take care of your condition
if(get_the_author_meta( "feature_package", $user_id ) && get_the_author_meta( "premium_package", $user_id )){
$u = new WP_User( $user_id );
$u->set_role('author'); // please replace with your required role ie: delar
}else{
$u = new WP_User( $user_id );
$u->set_role('subscriber');
}
}
For more details please follow links below:
Just for explanation, what above code is going to do. When any user will update his profile. The condition will check if there are values set in user custom fields, then the role of user will get changed according to passed value like “author” in this example.
Thanks!