Hi @kylepflueger
What custom code do you have so far? Can you please share it here so we can review it?
Regards,
Thanks for the quick follow up @champsupertramp. Please see below
add_action( 'um_post_registration_pending_hook', 'function_name', 10, 2 );
function check_for_promo_code( $user_id, $args ) {
um_fetch_user( $user_id );
$promo_codes = array('ecss_amp', 'ECSS_AMP');
$user_promo = um_user('promo_code');
if (in_array($user_promo, $promo_codes )) {
$ultimatemember->user()->approve();
} else {
$ultimatemember->user()->pending();
}
}
@champsupertramp I was able to get the approval portion working using this code below:
add_action( 'um_post_registration_pending_hook', 'check_for_promo_code', 10, 2 );
function check_for_promo_code( $user_id, $args ) {
global $ultimatemember;
um_fetch_user( $user_id );
$promo_codes = array('ecss_amp', 'ECSS_AMP');
$user_promo = um_user('promo_code');
if (in_array($user_promo, $promo_codes )) {
um_fetch_user( $user_id );
UM()->user()->approve();
} else {
um_fetch_user( $user_id );
UM()->user()->pending();
}
}
However, I am unable to successfully set the users role within that same function. I am trying to use the set_role() method as such:
add_action( 'um_post_registration_pending_hook', 'check_for_promo_code', 10, 2 );
function check_for_promo_code( $user_id, $args ) {
global $ultimatemember;
um_fetch_user( $user_id );
$promo_codes = array('ecss_amp', 'ECSS_AMP');
$user_promo = um_user('promo_code');
if (in_array($user_promo, $promo_codes )) {
um_fetch_user( $user_id );
UM()->user()->set_role('role_name_is_here');
UM()->user()->approve();
} else {
um_fetch_user( $user_id );
UM()->user()->pending();
}
}
Does this need to be handled in a separate filter or action? Any tips are greatly appreciated! Thanks!
Hi @kylepflueger
Try using the code snippet to add a user role:
if ( in_array($user_promo, $promo_codes ) ) {
$u = new WP_User( $user_id );
// Add role
$u->add_role( 'role_name_is_here' );
}
Regards,
Hey there!
This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.
Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. 🙂
Regards,