title: WooCommerce: Filter Admin orders by product attribute term
body: <p>I have a store with many variable products. All orders are custom made specifically for the customer. This means that when we receive the product in the warehouse we need to find the order of the specific product. Right now we simply have to manually check most orders.</p>
  <p>What we want to do that will save us valuable time is search orders by custom attribute terms. For example: We use attribute &quot;size&quot; for custom orders. We have 24 &quot;size&quot; terms (e.g. &quot;12cm&quot;, :16cm&quot; etc). We want to find the order based on the size term. For example: Find all orders who's size is &quot;48cm&quot;.</p>
  <p>Based on <em><a href="https://stackoverflow.com/questions/37762856/extending-search-in-backend-orders-list-for-product-items-by-id-or-by-sku/37766717#37766717">Extending search in backend orders list for product items by id or by sku</a></em>, here is my code attempt:</p>
  <pre><code>add_filter( 'woocommerce_shop_order_search_fields', function ($search_fields ) {
      $orders = get_posts( array( 'post_type' =&gt; 'shop_order' ) );
  
      foreach ($orders as $order_post) {
          $order_id = $order_post-&gt;ID;
          $order = new WC_Order($order_id);
          $items = $order-&gt;get_items();
      
          foreach( $order-&gt;get_items() as $item_id =&gt; $item_values ) {
              if ( version_compare( WC_VERSION, '3.0', '&lt;' ) ) {
                  $product_id = $item_values['product_id'];
              } else {
                  $product_id = $item_values-&gt;get_product_id();
              }
               $attribute = $item_values-&gt;get_data();
               
              // attribute value
              $value = $attribute['value'];
              
              // attribute slug
              $slug = $attribute['size'];
              
              add_post_meta($order_id, $slug, $value, true); //
          }
      }
      return array_merge($search_fields, array($slug));
  }); 
  </code></pre>
  <p>But It didn't work. Any help is appreciated.</p>