Membership redirect not working correctly

I want to have users register as "basic" users first (for a free membership), then redirect them to the membership page to see the options for our premium plans and subscribe directly to a free trial and afterward get redirected to the homepage instead of the upgrade page again.

This is the code I am using:

'<?php
add_action( 'ms_controller_frontend_register_user_complete', 'ms_custom_after_registration', 10, 3 );
function ms_custom_after_registration( $user, $request, $controller ) {
if ( !empty( $request['membership_id'] ) ) {
$membership_id = $request['membership_id'];
if ( $membership_id == 2939 ) { //Select the id of the membership to check after registration
$custom_url = "https://thebuzzard.org/memberships/";
wp_safe_redirect( $custom_url );
exit;
}
}
}'

Code above provided by one of the developers should handle the redirect. Although after a user clicks to sign up to a free membership, the redirect works, but a user is not subscribed to a free membership.

  • Paul Kevin

    Hey there Dario ,

    Hope you are well today. To add the user to the membership after registration, please use the below code

    <?php
    add_action( 'ms_controller_frontend_register_user_complete', 'ms_custom_after_registration', 10, 3 );
    function ms_custom_after_registration( $user, $request, $controller ) {
    	if ( !empty( $request['membership_id'] ) ) {
    		$membership_id = $request['membership_id'];
    		if ( $membership_id == 2939 ) { //Select the id of the membership to check after registration
    			MS_Model_Relationship::create_ms_relationship( $membership_id, $user->id );
    			$custom_url = "https://thebuzzard.org/memberships/";
    			wp_safe_redirect( $custom_url );
    			exit;
    		}
    	}
    }
    ?>

    Kindly let me know if you have any other questions.

    Warm Regards
    Paul Kevin

  • Felix

    Hi Paul Kevin,

    I tried your code.
    Unfortunately, it doesn't work as desired.

    It does allow to register and it does redirect to the correct page after registration.
    It even lists this new registered user as a member of the "basic" membership in the backend overview of members and it also confirms this in the /account page.

    BUT as a user, the menu doesn't change correctly to the menu for registered users and the "basic" user isn't granted the rights as a basic user by the system, i.e. he cannot access articles that should be accessible for basic users.

    You can try that out when you look at felixfrie91+probetest12@gmail.com versus felixfrie91+1000@gmail.com. The latter is a basic membership that works fully normal that I registered a few months ago. The +probetest12 one has been created today and faces the problems described above.

    For now, I will deactivate the mu-plugin again until I get further support.
    Thank you in advance.

    Best
    Dario

    • Paul Kevin

      Hey there Dario ,

      Hope you are well today. Kindly use the below code

      <?php
      add_action( 'ms_controller_frontend_register_user_complete', 'ms_custom_after_registration', 10, 3 );
      function ms_custom_after_registration( $user, $request, $controller ) {
      	if ( !empty( $request['membership_id'] ) ) {
      		$membership_id = $request['membership_id'];
      		if ( $membership_id == 2939 ) { //Select the id of the membership to check after registration
      			$new_subscription 						= MS_Model_Relationship::create_ms_relationship( $membership_id, $user->id );
      			$new_subscription->start_date 			= null; // Will calculate correct date.
      			$new_subscription->trial_expire_date 	= null;
      			$new_subscription->expire_date 			= null;
      			$new_subscription->status 				= MS_Model_Relationship::STATUS_ACTIVE;
      			$new_subscription->save();
      			$custom_url = "https://thebuzzard.org/memberships/";
      			wp_safe_redirect( $custom_url );
      			exit;
      		}
      	}
      }
      ?>

      Issue was the subscription was not activated. This should correct that.

      Warm Regards
      Paul Kevin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.