title: Bulk add new role to list of WooCommerce users
body: <p>I have a list of 141 customers that purchased a product from our WooCommerce site. I pulled the list using the UserInsights plugin (<a href="https://usersinsights.com/" rel="nofollow noreferrer">https://usersinsights.com/</a>). </p>
  
  <p>What I am trying to do is to bulk add a different role to these users on top of whatever they have and if they already have the new role to simply not do anything to that specific user. </p>
  
  <p>Using this article from UserInsights (<a href="https://usersinsights.com/woocommerce-change-customer-role/" rel="nofollow noreferrer">https://usersinsights.com/woocommerce-change-customer-role/</a>), I tried adding the following code to my functions.php, it shows that the code is executed, but the users never receive the new role. </p>
  
  <p>Here is the code I added to my functions.php:</p>
  
  <pre><code>function uiwc_set_custom_role() {
    //the slug of our newly created group
    $group_slug = 'homeschool-strong';
  
    //the role we want to change our users to
    $user_role = 'homeschool-strong';
  
    //telling WP which taxonomy we're looking into
    $taxonomy = 'usin_group';
  
    //getting the UI group information
    $term = get_term_by( 'slug', $group_slug, $taxonomy, 'ARRAY_A' );
  
    // getting the users from that group
    $id = $term['term_id'];
    $out = get_objects_in_term( $id, $taxonomy );
  
    //checking if there are any users
    if( ! empty( $out ) ) {
  
      //let's loop trhough all users
      foreach ( $out as $uid) {
    //get the user related to this ID
    $user = new WP_User($uid);
  
    //do not change the role of admins
    if( !user_can($user, 'administrator') ){
      //set the new role to our customer
      $user-&gt;$user-&gt;add_role($role);
    }
  
  }
  
  // just so you know the code worked
  echo "&lt;script&gt;alert('code run');&lt;/script&gt;";
  }
   }
  
  add_filter('admin_footer', 'uiwc_set_custom_role');
  </code></pre>
  
  <p>Would anyone know why when this code is executed the new role is not added to the users? Or maybe you know of a better way to add a new role to a list of WooCommerce users?</p>