• Resolved kpflueger

    (@kylepflueger)


    I’d like to set up a process in which a specific promo code entered in a registration form will automatically approve a user. I have tried a handful of solutions using the developer docs, but still having trouble getting it to work. Would love a hand in developing the right solution!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kylepflueger

    What custom code do you have so far? Can you please share it here so we can review it?

    Regards,

    Thread Starter kpflueger

    (@kylepflueger)

    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();
        }
    }
    Thread Starter kpflueger

    (@kylepflueger)

    @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!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    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,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    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,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Auto-approve w/ promo code’ is closed to new replies.