Notice: Undefined variable: string in /home/u665484253/domains/wpcodekit.com/public_html/wp-content/themes/twentytwenty-child/functions.php on line 61
How to redirect user on different page accounding to user (Customer, editor, admin, subscriber and etc)?
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 if(has_active_subscription($user->ID) || wc_customer_bought_product( $current_user->user_email, $current_user->ID,'9011')){ $redirect = home_url('/start-deal/'); } else { $redirect = home_url('/pricing/'); } } 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 );
Read More Posts
- How to fix woocommerce-rating-stars-bugs-sssss?
- Check User Has Already Purchased Product in woo-commerce?
- How to fix If value is infinity, empty and NaN in jQuery?
- How to create custom OTP login in woocommerce without plugin?
- How to download pdf file on browser instead of saving it on the server in fpdf?