title: Remove product after an order has been placed in WooCommerce
body: <p>I'm using the most recent versions of WordPress and WooCommerce.</p>
  <p>I'm aware this might seem weird out of context, but I wanna add a hook to my functions.php that removes a certain product by ID from an order after the order has been placed.</p>
  <p>Here is what I am working with so far:</p>
  
  <pre class="lang-php prettyprint-override"><code>add_action('woocommerce_new_order', 'custom_process_order', 10, 1);
  function custom_process_order($order_id) {
      $order = new WC_Order( $order_id );
      $items = $order-&gt;get_items();
      foreach ($items as $item) {
          if ($item-&gt;get_id()==10766) {
            $order-&gt;remove_item( $item-&gt;get_id() );
          }
      }
      return $order_id;
  }
  </code></pre>
  <p>I am trying to remove the product with the ID 10766 from the order if said product is part of the order.
  I took this from a different, older post here so the code itself might not be perfect. It definitely isn't working.</p>
  <p><strong>Update after some experimentation:</strong><br />
  With the help of Cameron Hurd, I tried the following code:</p>
  <pre class="lang-php prettyprint-override"><code>add_action('woocommerce_new_order', 'custom_process_order', 10, 1);
  
  function custom_process_order($order_id) {
      $order = new WC_Order( $order_id );
      $items = $order-&gt;get_items();
      foreach ($items as $item) {
          if ($item-&gt;get_id() === 10766) {
              $order-&gt;remove_item( $item-&gt;get_id() );
          }
      }
  
      $order-&gt;save_items();
  
      return $order_id;
  }
  </code></pre>
  <p>This seemed promising, but pressing the checkout button will submit an empty order while also throwing an empty WooCommerce error message leaving the user on the checkout page.</p>
  <p>After this I had 2 ideas:<br />
  1.) Changing <code>remove_item</code> to <code>wc_delete_order_item</code>. I really don't know the difference and changing it didn't seem to make a difference either.<br />
  2.) Changing the hook so it happens after the order is in the back end. I tried changing it from <code>woocommerce_new_order</code> to <code>woocommerce_thankyou</code>. This however broke the thank you page in addition to doing nothing to the order.</p>
  <p>This is what I'm sitting with now:</p>
  <pre class="lang-php prettyprint-override"><code>add_action('woocommerce_checkout_create_order', 'custom_process_order', 10, 1);
  
  function custom_process_order($order_id) {
      $order = new WC_Order( $order_id );
      $items = $order-&gt;get_items();
      foreach ($items as $item) {
          $current_item_id = $item-&gt;get_id();
          if ( $current_item_id === 10766) {
              $order-&gt;remove_item($current_item_id);
          }
      }
  
      $order-&gt;save_items();
  
      return $order_id;
  }
  </code></pre>
  <p>Still looking for a working answer.</p>