I'm using Wordpress with Ultimate Member and I'm setting up so that content will be blocked if the user is not registered or below age 21.
I have it so that they are not able to see the content right now by default whether they're registered or not. I'd like to add a bit of code to check their D.O.B. against the current date and if above 21 put them into the customer group that the products are visible for.
Any suggestions or help at all is appreciated :)
I tried adapting this solution but I believe that uses WP-LOGIN, which bypasses Ultimate Member. Also I don't know the language or how to debug.. so my code alterations may have just broken it or such. How to set new user to a group automatically according to their role in Wordpress
added this to a functions.php under /wp-includes/ with the recommended plugin installed and groups created
I'm not sure what the "10" and "1" refer to here or where to find documentation.
add_action( 'user_register', 'myAssignGroup', 10, 1 );
function myAssignGroup($birth_date){
//Set user age based off now
user_age = floor((current_time('U') - $birth_date)/(365*24*60*60));
$user = new WP_User($user_age);
foreach ($user->age as $age) {
//for teacher
if ($age<21) {
wp_set_object_terms($user_age, 36, 'user-group', FALSE); //by tag_ID
//wp_set_object_terms($user_age, my-first-group, 'user-group', FALSE);//by term slug
}
//for student
else {
wp_set_object_terms($user_age, 37, 'user-group', FALSE);
}
}
}
****** EDIT-WORKING ******
Using the code found here, and the 'Plugin File Editor' option found under the 'Plugins' option on the sidebar, I got it working.
In case anyone else is having troubles with the non-updated instructions/documentation: I added the code to the 'Ultimate Member' plugin itself under "/Inlcudes/core/" in the "um-actions-form.php" file.
****** EDIT-WORKING ******