user_register hook fires immediately after a new user is registered. so you have to add action on this hook. You can add below example code in your active theme’s function file.
Example :
add_action( 'user_register', 'redirect_user_based_on_role', 10, 1 );
function redirect_user_based_on_role( $user_id ) {
// Get the user object.
$user = get_userdata( $user_id );
// Get all the user roles as an array.
$user_roles = $user->roles;
// Check if the role you are interested in, is present in the array.
if ( in_array( 'customer', $user_roles, true ) ) {
// Do something.
wp_redirect( 'https://mysite.com/shop' );
exit;
}
if ( in_array( 'endorser', $user_roles, true ) ) {
// Do something.
wp_redirect( 'https://mysite.com/landingpage' );
exit;
}
}