• Resolved mairh93

    (@mairh93)


    Hello all,

    I want after the log in to redirect the Store Vendor and the customer to two different url. I used in the snippet code plug in the code below, bur it doesn’t work.

    add_filter( ‘user_registration_login_redirect’, ‘ur_redirect_back’, 10, 2 );function ur_redirect_back( $redirect_url, $user ) {
    $current_user = (object) $user;
    $roles = isset( $current_user->roles ) ? (array) $current_user->roles : array();
    if ( in_array( ‘Store Vendor’, $roles, true ) ) {
    $redirect_url = ‘https://my-site.com/store-manager’;
    } elseif ( in_array( ‘customer’, $roles, true ) ) {
    $redirect_url = ‘https://my-site.com/home’;
    }
    return $redirect_url;
    }

    *redirect_url : I put the url of the page that I want
    Do you have any idea?

    Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi @mairh93,

    Please try the following code snippet on your site to redirect after login according to the roles.

    add_filter( 'user_registration_login_redirect', function( $redirect_url, $current_user ) {
                $current_user = (object) $current_user;
                $roles = isset( $current_user->roles ) ? (array) $current_user->roles : array();
                if ( in_array( 'subscriber', $roles, true ) ) {
                    $redirect_url = 'https://subscribers-come-here.com';
                }
                if ( in_array( 'customer', $roles, true ) ) {
                    $redirect_url = 'https://customers-come-here.com';
                }
                return $redirect_url;
            }, 10, 2 );

    Regards!

    Thread Starter mairh93

    (@mairh93)

    Thank you for your time..It doenst work. After the log in I see the front page and not the page that I put in the url

    View post on imgur.com

    • This reply was modified 2 years, 9 months ago by mairh93.
    Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi @mairh93,

    We have tested the code properly and sent it to you. Please let us with which user role you have tried to login.

    Suggestion: Register one new user as a customer using the user registration form and try to login into your site after registration.

    Regards!

    Thread Starter mairh93

    (@mairh93)

    So when I log in as Store Vendor it works, as after log in I see the /store-manager page.

    But, when I log in as a customer, after the log in I continue to be in the /my-account page : image below

    View post on imgur.com

    Thank you!

    • This reply was modified 2 years, 9 months ago by mairh93.
    Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi @mairh93,

    We tested the code multiple times but did not find any issue. Could you please try a different URL for customer role redirection?

    Regards!

    Thread Starter mairh93

    (@mairh93)

    Hello,

    So after investigation, I think that the problem is in the code snippet plug in..I will check why it doesn’t work and I will try to check again your code.

    Thank you for your time!

    Thread Starter mairh93

    (@mairh93)

    Hello,

    I have one question…the code that you provided to me works after the default use registration form ? or I need to create a custom one ?

    Thank you!

    Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi @mairh93,

    The provided codes work based on the user role, so you do not need to create a new registration form.

    We will mark this thread as resolved. If you need assistance with the user registration, please create a new ticket. We will get back to you as soon as possible.

    ?Also, if you have a moment to spare, we would appreciate your reviewing our plugin. Please click on this link https://www.ads-software.com/support/plugin/user-registration/reviews and share your thoughts about our team and our plugin. We would love to hear from you.
    ?
    Thanks!

    Thread Starter mairh93

    (@mairh93)

    Hello,

    Unfortunaltely the php code dont work in my case for rederecting the user. I thought that the problem was with the Code snippet plug in, but I put directly your code in the function.php and nothing happens…the user continue to go to the /my-account page after the log in and not in the home page as I wanted.

    Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi @mairh93,

    It might be a conflict, or you have already set redirection for customers, so it is not working for you. Please check this documentation link https://docs.wpeverest.com/user-registration/docs/how-to-check-plugin-theme-conflict/ and follow the instruction kindly. This will let you know the cause of the error.

    Let me know if it helps, and I will get back to you.
    Regards!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Redirect dont work’ is closed to new replies.