title: Woocommerce remove item from cart - PHP
body: <p>The task is to make a item not purchasable if a customer already bought it.
  So my solution was to remove the product if the customer add it in the cart.</p>
  
  <pre><code>add_action( 'woocommerce_add_to_cart', 'testtt');
  
  function testtt()
  { 
      $token = $_SESSION['******token'];  
      $dataservice = *******Service::getService('DataService');
      $list = $dataservice-&gt;getArticleBlacklist( $token );
  
  foreach( WC()-&gt;cart-&gt;get_cart() as $cart_item_key =&gt; $cart_item ) 
  {
      //Get SKU by product_id or if available variation_id
      if( $cart_item['variation_id'] != 0  )
      {
          $prototype = new WC_Product( $cart_item['variation_id'] );      
          $prod_art_id = $prototype-&gt;get_sku();   
      }
      else
      {
          $prototype = new WC_Product( $cart_item['product_id'] ) ;       
          $prod_art_id = $prototype-&gt;get_sku();   
      }
  
      //convert SKU from STRING into INTEGER
      $x = intval( $prod_art_id );
  
      //Remove product
      if( $x == $list-&gt;int )
      {       
          WC()-&gt;cart-&gt;remove_cart_item( $cart_item_key );
      }
      else
      {
          continue;           
      }       
  }
  </code></pre>
  
  <p>I tried some different art of code 
   for example: </p>
  
  <pre><code>//Remove product
  if( $x == $list['int'] )
  {    
  </code></pre>
  
  <p>And a lot of other things... nothing works. But the thing is that I know it works. Because if I change </p>
  
  <pre><code>add_action( 'woocommerce_add_to_cart', 'testtt');
  </code></pre>
  
  <p>into </p>
  
  <pre><code>add_action( 'parse_reqeust', 'testtt');
  </code></pre>
  
  <p>the code does what it has to do. I am very confused because I did some days ago a code with the same task and it still works (There I had to remove ALL OTHER products from cart if the 'marked' product was add to cart ).</p>
  
  <p>Info: in $list I am getting the Article SKU from the "blacklisted" product as an</p>
  
  <pre><code> `object {["int"]=&gt;int(*number*)}` .
  </code></pre>
  
  <p>I hope someone could help me. Thanks^^</p>