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 = $request;

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.