i am trying to automatically group users when they register according to a list of selections in the register form. I am using WP User Group plugin to make groups and Ultimate Member to register users.
I didn't manage to figure out a working solutions for my issue. Can anyone help me realize what i am missing.
add_action( 'user_register', 'AutoGroup', 10, 1 );
function AutoGroup($user_id){
$user_args = get_user_meta($user_id,'activity_domain' , true);
if ($user_args == 'Public Services'){
wp_set_object_terms($user_id, 61, 'user-group', FALSE);
}
else if ( $user_args == 'Private Services'){
wp_set_object_terms($user_id, 62, 'user-group', FALSE);
}
else{
wp_set_object_terms($user_id, 63, 'user-group', FALSE);
}
}
Later edit: I have 3 groups: "Public Services", "Private Services" and "Others" the problem i am facing is that all user who register on the site automatically goes into the "Other" group, so i am guessing that "$user_args" variable doesn't take any value. I have also tried this code but no luck.
add_action( 'user_register', 'AutoGroup', 10, 1 );
function AutoGroup($user_id){
$user = new WP_User($user_id);
foreach ($user->activity_domain as $user_args){
if ($user_args == 'Public Services'){
wp_set_object_terms($user_id, 61, 'user-group', FALSE);
}
else if ( $user_args == 'Private Services'){
wp_set_object_terms($user_id, 62, 'user-group', FALSE);
}
else{
wp_set_object_terms($user_id, 63, 'user-group', FALSE);
}
}
I dont know what i am missing. I dont know exactly how to debug my code and see in real time how the variable takes values but i have made a shortcode with the exact same code and when i run the shortcode on a page it works perfectly, and when i say perfectly i mean that it query the database for the logged user and displays his meta_value .
I have to specify that i am now trying to learn PHP and Wordpress and i really count on your help.
Edit
link underneath the tags. The last thing you want is for people to think you've already gotten a solution