Support » Plugin: Login with Vipps » Custom redirect url after login

  • Hi, intead of having to edit the core files. Is there a simple way to have a spesific url after completed login? With woocommerce active it just redirects to account page.

    Maybe a simple function filter?

    Thanx! šŸ™‚
    Marius

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author iverok

    (@iverok)

    Yes, there are several ways. First, the WooCommerce login and the “ordinary” login (on wp-login.php) are actually two different functions, so they behave slightly differently.

    For WooCommerce logins you can just use the filter

    apply_filters('login_with_vipps_woo_login_redirect', $link, $user, $session);

    Your second argument here is the WC_User object so you can redirect different users to different places; the $session is an array with the raw data sent from Vipps.

    For logins on the wp-login.php page, only the standard WP ‘login_redirect’ filter is used, which normally redirects to the users profile page. However, just before this is called, an action

    do_action('continue_with_vipps_before_user_login', $user, $session);

    – is run, and if this has been run (did_action('continue_with_vipps_before_user_login');) you know this is a Vipps login if you want to treat those differently. You can also use this hook to modify the login_redirect filter directly, which is what the Woo login does.

    You can also just use the standard login_redirect filter with a very late priority if you don’t care how they log in.

    Error logins are handled completely differently, because of how the error messages need to be propagated. For woocommerce the standard rules should work ok, but if you need to handle this specially too, there are filters for this also.

    Thread Starter djeshm

    (@djeshm)

    Thank you for your answer! Was able to make two different redirects now based on normal login and woocommerce login.

    Kind regards
    Marius

    • This reply was modified 1 year, 3 months ago by djeshm.
    • This reply was modified 1 year, 3 months ago by djeshm.

    Hi @djeshm

    As another easy alternative is to write a little JavaScript that listens to the “logged-in” tag in your page. Your theme must support this tag.

    <script>
    
    var isLoggedIn = false;
    
    // This line checks if user is logged in and set isLoggedIn variable
     if (document.body.classList.contains('logged-in')) {isLoggedIn = true;} 
    
    if (isLoggedIn == true){
    // If the customer is logged into WordPress, redirect the user to another page
     window.location.href = 'https://www.domain.no/page';
    
     } 
    </script>

    Use it for what it is worth.

    Cheers
    Horgster

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom redirect url after login’ is closed to new replies.