Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce/Wordpress - Redirect User Login to Homepage

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?

like image 445
Whit Avatar asked Aug 14 '12 18:08

Whit


3 Answers

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.

like image 92
Sam Avatar answered Oct 16 '22 12:10

Sam


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;
}
like image 33
Dhirendra Kumawat Avatar answered Oct 16 '22 11:10

Dhirendra Kumawat


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(); ?>" />
like image 45
Tomanow Avatar answered Oct 16 '22 12:10

Tomanow