Woocommerce/Wordpress - Redirect User Login to Homepage

20,120

Solution 1

Use this code on functions.php

add_filter('woocommerce_login_redirect', 'wc_login_redirect');
function wc_login_redirect( $redirect_to ) {
     $redirect_to = 'https://www.google.co.in/';
     return $redirect_to;
}

Solution 2

You can download http://wordpress.org/extend/plugins/peters-login-redirect/ and replace this in the widget-login.php

<input type="hidden" name="redirect_to" class="redirect_to" value="<?php echo $redirect_to; ?>

with

<input type="hidden" name="redirect_to" class="redirect_to" value="<?php echo site_url('/wp-content/plugins/peters-login-redirect/wplogin_redirect_control.php/'); ?>" />

That way you can use peters login redirect to redirect globally and specific users using the woocommerce login widget.

Make sure you change "Use external redirect file. Set this to "Yes" if you are using a plugin such as Gigya that bypasses the regular WordPress redirect process (and allows only one fixed redirect URL). Then, set the redirect URL to %s" in the settings to "YES".

Hope this helps.

Solution 3

That fix they provide only works if you are utilizing the login widget. All you need to do it redirect the user after logging in to your home page is to add this to your login form:

<input type="hidden" name="redirect" value="<?php echo get_home_url(); ?>" />
Share:
20,120
Whit
Author by

Whit

Updated on September 25, 2020

Comments

  • Whit
    Whit over 3 years

    I have searched for the answer to this, used plugins and still nothing works. I would like users of my site to be redirected to the home page after they login/register.

    Currently, the user logs in and is redirected to the my account page.

    Woocommerce provides this code, but it failed to work for me:

    /*
     * goes in theme functions.php or a custom plugin
     *
     * By default login goes to my account
     **/
    add_filter('woocommerce_login_widget_redirect', 'custom_login_redirect');
    
    function custom_login_redirect( $redirect_to ) {
         $redirect_to = 'http://anypage.com';
    }
    

    I have also attempted to use the Peter's Redirect plugin but it does not work since woocommerce bypasses wp-login.php.

    Thoughts?