Created
          February 3, 2017 07:34 
        
      - 
      
- 
        Save rynaldos-zz/869577bd6cd8c5a53486b72e23e4aec5 to your computer and use it in GitHub Desktop. 
    [WooCommerce] Redirect users from my-account page (based on role)
  
        
  
    
      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
    
  
  
    
  | add_filter('woocommerce_login_redirect', 'wc_login_redirect', 10, 2 ); | |
| function wc_login_redirect( $redirect_to, $user ) { | |
| $role = $user->roles[0]; | |
| $myaccount = get_permalink( wc_get_page_id( 'myaccount' ) ); | |
| if( $role == 'customer' ) { | |
| $redirect_to = home_url(); | |
| } | |
| return $redirect_to; | |
| } | |
| // Use the following to redirect this role to previous visited page (if possible) OR homepage | |
| // $redirect_to = wp_get_referer() ? wp_get_referer() : home_url(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment