• Resolved stivenson2005

    (@stivenson2005)


    Hey there,

    We are using Vipps login and works wonderful!

    However noticed that when an Admin role logs in using Vipps login, the user gets redirected to their profile at every single login with vipps.

    Tried using the Woocommerce custom login snippet but wont work if logged in with vipps.

    This what i used to redirect everyone to the dashboard (My-account page)

    function wc_custom_user_redirect( $redirect, $user ) {
      // Get the first of all the roles assigned to the user
      $role = $user->roles[0];
      $dashboard = admin_url();
      $myaccount = get_permalink( wc_get_page_id( 'shop' ) );
      if( $role == 'administrator' ) {
        //Redirect administrators to the dashboard
        $redirect = $dashboard;
      } elseif ( $role == 'shop-manager' ) {
        //Redirect shop managers to the dashboard
        $redirect = $myaccount;
      } elseif ( $role == 'editor' ) {
        //Redirect editors to the dashboard
        $redirect = $myaccount;
      } elseif ( $role == 'author' ) {
        //Redirect authors to the dashboard
        $redirect = $myaccount;
      } elseif ( $role == 'customer' || $role == 'subscriber' ) {
        //Redirect customers and subscribers to the "My Account" page
        $redirect = $myaccount;
      } else {
        //Redirect any other role to the previous visited page or, if not available, to the home
        $redirect = wp_get_referer() ? wp_get_referer() : home_url();
      }
      return $redirect;
    }
    add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 ); 
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Iver Odin Kvello

    (@iverok)

    Do I understand correctly in that you want to send *all* users to the Woo profile page instead of the WP profile page? For this you should probably change the “login_redirect” filter, which affects all logins.

    There are actually two “login_redirect” branches using the Vipps plugin, that has two different “applications”. The first, on the wp-login page, will use the “wordpress” application and per usual go to the profile page of the user. Woo changes this to the “my account” page for “customers” only. This works the same way as standard WP logins.

    The other, with the application “woocommerce” will actually log all users into the “my account” page, unless there is something in their cart, in which case it will go to checkout. This is used on all the Woocommerce pages, so if you log in via those, you should end up on a Woo page.

    Both of these redirects can be changed using the login redirect filter with a high enough priority:

    add_filter('login_redirect', 'my_login_redirect_function', 999, 3);

    If you need to modify just the “Log in with Vipps on a WooCommerce page” redirect, you can use the filter

    add_filter('login_with_vipps_woo_login_redirect', 10, 3)

    – the second argument is the User object, the third is the Vipps session.

    Thread Starter stivenson2005

    (@stivenson2005)

    Thank you for your answer, helped me to get to what I was after!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect to My account’ is closed to new replies.