Skip to content

Instantly share code, notes, and snippets.

@rynaldos-zz
Created February 3, 2017 07:34
Show Gist options
  • Save rynaldos-zz/869577bd6cd8c5a53486b72e23e4aec5 to your computer and use it in GitHub Desktop.
Save rynaldos-zz/869577bd6cd8c5a53486b72e23e4aec5 to your computer and use it in GitHub Desktop.
[WooCommerce] Redirect users from my-account page (based on role)
add_filter('woocommerce_login_redirect', 'wc_login_redirect', 10, 2 );
function wc_login_redirect( $redirect_to, $user ) {
$role = $user->roles[0];
$myaccount = get_permalink( wc_get_page_id( 'myaccount' ) );
if( $role == 'customer' ) {
$redirect_to = home_url();
}
return $redirect_to;
}
// Use the following to redirect this role to previous visited page (if possible) OR homepage
// $redirect_to = wp_get_referer() ? wp_get_referer() : home_url();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment