• Resolved electronica23

    (@electronica23)


    I have applied the recipe that redirect members to a specific page based on their membership level after login (https://www.paidmembershipspro.com/redirect-members/) but when a user logs in from the checkout page to purchase another membership, it does not redirect me back to the payment page, but instead redirects me to the page of their current level just like the previous recipe.

    What I can do?

    thanks you so much!!!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Jarryd Long

    (@jarryd-long)

    Hi there, thank you for reaching out to the Paid Memberships Pro team.

    The login link on the checkout page doesn’t track where the user comes from by default. You would need to hook into the pmpro_checkout_login_redirect filter (https://www.paidmembershipspro.com/hook/pmpro_login_redirect_url/) and track the current level so that the member is redirected back to the same page after logging in.

    Kind Regards,
    Jarryd
    Support Manager at Paid Memberships Pro

    Thread Starter electronica23

    (@electronica23)

    Hello, thank you for your quick response.
    I am using this code but it is not working

    function pmpro_checkout_login_redirect( $redirect_to, $request = NULL, $user = NULL ) {
    global $wpdb;
    $is_logged_in = ! empty( $user ) && ! empty( $user->ID );

    if ( $is_logged_in && empty( $redirect_to ) ) {
    // Can't use the pmpro_hasMembershipLevel function because it won't be defined yet.
    $is_member = $wpdb->get_var( "SELECT membership_id FROM $wpdb->pmpro_memberships_users WHERE status = 'active' AND user_id = '" . esc_sql( $user->ID ) . "' LIMIT 1" );
    if ( $is_member ) {
    $redirect_to = pmpro_url( 'account' );
    } else {
    $redirect_to = pmpro_url( 'levels' );
    }
    }

    // Custom redirect filters should use the core WordPress login_redirect filter instead of this one.
    // This filter is left in place for PMPro versions dating back to 2014.
    return apply_filters( 'pmpro_checkout_login_redirect', $redirect_to, $request, $user );
    }
    add_filter( 'login_redirect','pmpro_checkout_login_redirect', 10, 3 );

    Plugin Support Jarryd Long

    (@jarryd-long)

    Please replace your function with the following, this should do the trick:

    function pmpro_checkout_login_redirect( $redirect_to, $request = NULL, $user = NULL ) {
    global $wpdb;
    $is_logged_in = ! empty( $user ) && ! empty( $user->ID );

    if ( $is_logged_in && empty( $redirect_to ) ) {
    // Can't use the pmpro_hasMembershipLevel function because it won't be defined yet.
    $is_member = $wpdb->get_var( "SELECT membership_id FROM $wpdb->pmpro_memberships_users WHERE status = 'active' AND user_id = '" . esc_sql( $user->ID ) . "' LIMIT 1" );
    if ( $is_member ) {
    $redirect_to = pmpro_url( 'account' );
    } else {
    $redirect_to = pmpro_url( 'levels' );
    }
    }

    return $redirect_to;
    }
    add_filter( 'pmpro_checkout_login_redirect','pmpro_checkout_login_redirect', 10, 3 );

    Kind Regards,
    Jarryd
    Support Manager at Paid Memberships Pro

    Thread Starter electronica23

    (@electronica23)

    Hello, it doesn’t work. When I log in from the “Already have an account? Sign in here” link on the checkout page, it does not return me to the checkout page.

    Plugin Support Jarryd Long

    (@jarryd-long)

    I’m afraid I can’t replicate this behavior as it worked when I tested it.

    Please navigate to Memberships > Settings > Pages and scroll down to the Login Page dropdown – please let me know what yours is set to? A page with the pmpro_login shortcode on it or ‘Use the WordPress Default’?

    Kind Regards,
    Jarryd
    Support Manager at Paid Memberships Pro

    Thread Starter electronica23

    (@electronica23)

    Hello!

    I am using a page with the pmpro_login shortcode.

    Thread Starter electronica23

    (@electronica23)

    I want to configure that link and I can’t, it doesn’t return me to the payment page.

    I have this code to redirect users based on their membership.

    /* ***** Redirecciones de LOGIN - Sample code to update login redirects for member */

    function custom_login_redirect( $redirect_to, $request, $user ) {
    if (pmpro_hasMembershipLevel(1, $user->ID)) {
    return "/portal/";
    }


    elseif (pmpro_hasMembershipLevel(5, $user->ID)) {
    return home_url( '/portal-1/' );
    }

    elseif (pmpro_hasMembershipLevel(6, $user->ID)) {
    return home_url( '/portal-2/' );
    }


    elseif ( is_array( $user->roles ) && in_array( 'customer', $user->roles ) ) {
    return home_url( '/escritorio/' );
    }

    return home_url();
    }
    add_filter( 'login_redirect', 'custom_login_redirect', 10, 3 );

    and I am using this code so that when I log in from the “Already have an account? Sign in here” link on the checkout page, it return me to the checkout page and not working ??

    function pmpro_checkout_login_redirect( $redirect_to, $request = NULL, $user = NULL ) {
    global $wpdb;
    $is_logged_in = ! empty( $user ) && ! empty( $user->ID );

    if ( $is_logged_in && empty( $redirect_to ) ) {
    // Can't use the pmpro_hasMembershipLevel function because it won't be defined yet.
    $is_member = $wpdb->get_var( "SELECT membership_id FROM $wpdb->pmpro_memberships_users WHERE status = 'active' AND user_id = '" . esc_sql( $user->ID ) . "' LIMIT 1" );
    if ( $is_member ) {
    $redirect_to = pmpro_url( 'account' );
    } else {
    $redirect_to = pmpro_url( 'levels' );
    }
    }

    return $redirect_to;
    }
    add_filter( 'pmpro_checkout_login_redirect','pmpro_checkout_login_redirect', 10, 3 );
    Plugin Support Jarryd Long

    (@jarryd-long)

    Because there’s multiple redirects in play here something is probably overlapping and causing the referrer that we set on the checkout page link to be ignored.

    I would recommend adding a check in your login_redirect function at the top before anything else to see if $redirect_to is not empty, then use that value before working out anything else below it.

    Kind Regards,
    Jarryd
    Support Manager at Paid Memberships Pro

    Plugin Support Jarryd Long

    (@jarryd-long)

    Because there have not been any recent updates to this topic, we will be changing the status to resolved. If you have any other questions regarding this issue please start a new topic for each question to ensure we can provide the best support possible.

    If you’re enjoying Paid Memberships Pro, would you mind rating it 5-stars to help spread the word? https://www.ads-software.com/support/plugin/paid-memberships-pro/reviews/

    Kind Regards,
    Jarryd
    Support Manager at Paid Memberships Pro

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Login Redirects Based On Membership Level’ is closed to new replies.