title: WooCommerce programmatically deleting from cart
body: <p>How do I programmatically remove an item from the Woocommerce cart using AJAX? I tried putting a function in my functions.php file and accessing that but nothing gets deleted. I tried hard-coding product 299 but it doesn't delete. Here's what I did:</p>
  
  <p>functions.php</p>
  
  <pre><code>function remove_item_from_cart() {
      $cart = WC()-&gt;instance()-&gt;cart;
      $id = 299;
      $cart_id = $cart-&gt;generate_cart_id($id);
      $cart_item_id = $cart-&gt;find_product_in_cart($cart_id);
  
      if($cart_item_id){
         $cart-&gt;set_quantity($cart_item_id, 0);
      }
      return true;
  }
  </code></pre>
  
  <p>themes/mine/main.js</p>
  
  <pre><code>$.ajax({
      type: 'POST',
      dataType: 'text',
      url: "http://www.../wp/wp-content/themes/mine/functions.php",
      data: {
          action: 'remove_item_from_cart'
      },
      success: function( data ) {
          console.log(data);
      }
  });
  </code></pre>