Created
February 26, 2020 12:07
-
-
Save BoyetDgte/d0627b1e81e2929e95314d09be9425b5 to your computer and use it in GitHub Desktop.
Redirect users to a different URL(default is My Account) after WooCommerce login.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// After login, users (customers and subscribers only) are redirected to the "Video Library" page -> get_permalink( $post = 6913 ); | |
function wc_custom_user_redirect( $redirect, $user ) { | |
// Get the first of all the roles assigned to the user | |
$role = $user->roles[0]; | |
$dashboard = admin_url(); | |
// video library URL | |
$videolibrary = get_permalink( $post = 6913 ); | |
if( $role == 'administrator' || $role == 'shop-manager' || $role == 'editor' || $role == 'author' ) { | |
//Redirect above roles to the dashboard | |
$redirect = $dashboard; | |
} elseif ( $role == 'customer' || $role == 'subscriber' ) { | |
//Redirect customers and subscribers to the "Video Library" page | |
$redirect = $videolibrary; | |
} else { | |
//Redirect any other role to the previous visited page or, if not available, to the home | |
$redirect = wp_get_referer() ? wp_get_referer() : home_url(); | |
} | |
return $redirect; | |
} | |
add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment