title: User redirect after login, depending on its role in WooCommerce
body: <p>In Woocommerce, I have code that changes the role if the user buys a certain product.</p>
  
  <pre><code>add_action( 'woocommerce_order_status_processing', 'change_role_on_purchase' );
  function change_role_on_purchase( $order_id ) {
  
  $order = new WC_Order( $order_id );
  $items = $order-&gt;get_items();
  
  foreach ( $items as $item ) {
      $product_name = $item['name'];
      $product_id = $item['product_id'];
      $product_variation_id = $item['variation_id'];
  
      if ( $order-&gt;user_id &gt; 0 &amp;&amp; $product_id == '3422, 3423, 3424' ) {
          update_user_meta( $order-&gt;user_id, 'paying_customer', 1 );
          $user = new WP_User( $order-&gt;user_id );
  
          // Remove role
          $user-&gt;remove_role( 'customer' ); 
  
          // Add role
          $user-&gt;add_role( 'subscriber' );
      }
  }
  }
  </code></pre>
  
  <p>I need to, after logging in to the site, if the user "Subscriber" and he has a certain "Subscription" product in the cart, then the system redirects it to the checkout page.</p>
  
  <p>I shall be very glad of your help!</p>
  
  <hr>
  
  <p><strong>Update:</strong> I will keep this variant. It can help other users.</p>
  
  <pre><code>add_filter('login_redirect', 'my_login_redirect', 10, 3);
  function my_login_redirect($redirect_to, $request, $user)
  {
  
  global $woocommerce;
  $items = $woocommerce-&gt;cart-&gt;get_cart();
  $ids_to_check = array(3422, 3423, 3424);
  
  foreach ($items as $item =&gt; $values) {
  $product_id = wc_get_product($values['data']-&gt;get_id());
  
  if (in_array($product_id, $id_to_check)) {
      //is there a user to check?
      if (isset($user-&gt;roles) &amp;&amp; is_array($user-&gt;roles)) {
          //check for subscribers
          if (in_array('subscriber', $user-&gt;roles)) {
              // redirect them to another URL, in this case, the homepage
              $url = get_permalink(get_option('woocommerce_checkout_page_id'));
  
              $redirect_to = $url;
          } 
      }
  
  }
  
  }
  
  return $redirect_to;
  }
  </code></pre>