Last active
October 21, 2016 15:18
-
-
Save rali14/970d21ccc5b4a78d3e12b2b703152581 to your computer and use it in GitHub Desktop.
Redirect users after registration
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
/** | |
* Redirect users to custom URL based on their role after login | |
* | |
* @param string $redirect | |
* @param object $user | |
* @return string | |
*/ | |
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(); | |
$myaccount = get_permalink( wc_get_page_id( 'myaccount' ) ); | |
if( $role == 'administrator' ) { | |
//Redirect administrators to the dashboard | |
$redirect = $dashboard; | |
} elseif ( $role == 'shop-manager' ) { | |
//Redirect shop managers to the dashboard | |
$redirect = $dashboard; | |
} elseif ( $role == 'editor' ) { | |
//Redirect editors to the dashboard | |
$redirect = $dashboard; | |
} elseif ( $role == 'author' ) { | |
//Redirect authors to the dashboard | |
$redirect = $dashboard; | |
} elseif ( $role == 'customer' || $role == 'subscriber' ) { | |
//Redirect customers and subscribers to the "My Account" page | |
$redirect = $myaccount; | |
} elseif ( $role == 'employer' ) { | |
//Redirect employer to your job dashboard page | |
$redirect = "http://LINKOYOURJOBDASHBOARDPAGE.com/JOBDASHBOARD"; // *********** CHANGE THIS URL FOR EMPLOYERS | |
} elseif ( $role == 'candidate ' ) { | |
//Redirect candidate ob dashboard page | |
$redirect = "http://LINKOYOURJOBDASHBOARDPAGE.com/JOBDASHBOARD"; // *********** CHANGE THIS URL FOR CANDIDATES | |
} 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_registration_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