max-kk
8/3/2016 - 9:10 AM

Redirect Woo cutomsers to profile and Not Woo Customers to Another page

Redirect Woo cutomsers to profile and Not Woo Customers to Another page

function check_is_customer_or_redirect_contest() {
  // Redirect if User does not have permissions
	$user = new WP_User( $user_ID );
	$is_customer = false;
	if ( !empty( $user->roles ) && is_array( $user->roles ) && in_array( 'customer', $user->roles ) ) {
  		$is_customer = true;
	}
  
  if ( $is_customer ) {
    $myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );
    if ( $myaccount_page_id ) {
      $myaccount_page_url = get_permalink( $myaccount_page_id );
    }  
    wp_safe_redirect( $myaccount_page_url );
  } else {
    wp_safe_redirect( '/contests/' );  // May be need replace URL
  }
  exit;
}

add_action( 'wp_login', 'check_is_customer_or_redirect_contest');