How to assign membership automatically after register on Membership 2

I have a membership that all users should be assigned to that after register. Default membership is not working for my needs so I need to assign with some actions/hooks maybe. How can I solve this?

  • Bo

    Also we have a second registration for "businesses" that i would like the users to use that membership registration for this membership so that it assigns these members to the business membership. Let me explain:

    So we have 3 memberships:
    - Business Membership
    - Trial Membership
    - Influercer Membership

    The trial membership is a trial to the influencer membership and these users can upgrade to the paid influencer membership. The business membership will have different access to different pages so i need These two registrations when a user registers to auto-assign to those memberships, also the influencer registration here: needs to use the buddypress registration but the business registration here: needs to use your membership form so they can be registered for their specific membership types.

  • James Morris

    Hello Bo

    I'm terribly sorry for the delay here. However, please keep in mind that what you are requesting goes outside the scope of normal support. It is a custom code request. Membership 2 Pro does not have this functionality natively built in and will require some custom logic to accomplish. Since this is a custom code request, I'm afraid this is lower in the queue than higher priority issues like fixing bugs.

    I understand this is urgent for you, but I'm afraid I cannot bump this issue higher in the queue for our SLS Team. If this is mission critical for you and you cannot afford to wait on our SLS Team's feedback, perhaps you can post your requirements on the Jobs & Pros board where fellow community members can bid on writing up a solution for you. Please note that the Pros on the Jobs & Pros board are not employed by WPMU DEV.

    However, if you would prefer to wait for the SLS Team, I assure you they will look into your issue as soon as possible. Thank you for your patience while we sort through this.

    Best regards,

    James Morris

  • Panos

    Hi Bo ,

    Apologies for delay!

    Of what I understand you need two things:
    1. Use different registration forms regarding the membership chosen
    2. It should add a membership by default to all users that register.

    1. For the first part, you can use something like the following:

    add_filter( 'ms_model_settings_get_custom_setting', function( $value, $group_name, $field_name, $option_model ){
    	if (
    		isset( $_REQUEST['step'] ) && $_REQUEST['step'] == 'payment_table' &&
    		isset( $_REQUEST['membership_id'] ) && $_REQUEST['membership_id'] == 5112
    		if( 'buddypress' == $group_name ){
    			$value = false;
    	return $value;
    }, 20, 4 );

    The above snippet will not show the BuddePress registration form if the membership with ID 5112 is selected.

    2. For your second request you can try one of the following:

    To target Membership plugin registration you can use following snippet:

    add_action( 'ms_model_member_create_new_user', function( $member ){
    	$subsription = $member->add_membership( 5193 );
    } );

    and replace 5193 with the membership ID you need to set.

    In case you use any other custom registration form, perhaps a more general approach would work:

    add_action( 'user_register', function( $user_id ){
    	$member = MS_Factory::load( 'MS_Model_Member', $user_id );
    	if ( $member ) {
    		$subsription = $member->add_membership( 5193 );
    } );

    You will need to replace the membership id I used in my examples (5193) to your own.

    Hope this helps :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.