• Resolved Efs

    (@stevendigital)


    Hello,

    I would like to ask if it is possible to be done the scenario bellow:

    When i log out as a customer , i want to be redirected to a specific page (Shop-page 1 for example).
    And when i am admin or shopkepper, i want to be redirected to the home page.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    Use something like this (Add this code to your themes function.php file).

    function auto_redirect_after_logout() {
    	// Get the user id
    	$user_id = get_current_user_id();
    	
    	// Get the user object.
    	$user_data = get_userdata( $user_id );
    	
    	// Get the user role
    	$user_roles = $user_data->roles;
    	
    	if ( in_array( 'customer', $user_roles, true ) ) {
    		wp_redirect( 'https://www.google.com/shop-page1' );
    		exit();		
    	} elseif ( in_array( 'administrator', $user_roles, true) ) {
    		wp_redirect( home_url() );
    		exit();			
    	} else {
    		wp_redirect( 'https://www.google.com/shop-page2' );
    		exit();	
    	}
    }
    add_action('wp_logout','auto_redirect_after_logout');

    Try this plugin
    https://www.ads-software.com/plugins/peters-login-redirect/

    • This reply was modified 5 years, 5 months ago by dangolprabesh.
    Thread Starter Efs

    (@stevendigital)

    Hello all,

    @crslz This worked . I modified it a bit more but it worked very good.Thank you for you help.

    @hyperprabesh I didn’t had the time to check the plugin as i used the answer from crslz. Thank you also for you answer.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirection in the log out of the user’ is closed to new replies.