woocommerce: widget login redirect

If the woocommerce_login_widget_redirect hook doesn’t work, it is because the redirection occurs even earlier, in the core wp_signon function. so we need to hook on to wp_login instead, for example

// allow user to redirect to the same page from the place that they login. The exception is wp-login.php
add_action( 'wp_login', 'my_login_redirect', 2, 2 );
function my_login_redirect( $login, $user ) {
  if ($_SERVER['REQUEST_URI'] != '/wp-login.php') {
  // redirect to the referrer
  wp_safe_redirect($_SERVER['HTTP_REFERER']);
  exit;
  }
}

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.