title: Woocommerce Select Orders which match multiple meta values
body: <p>I'm currently working on a plugin which was built for a bakery to email reports about orders. They have since opened another store and now the reports need to be split into separate emails depending on store location. </p>
  
  <p>I have the following sql query:</p>
  
  <pre><code>$sql = "SELECT o.order_item_id, o.order_item_name, o.order_id, po.post_date AS order_date_placed
          FROM wp_woocommerce_order_items AS o
          LEFT JOIN wp_woocommerce_order_itemmeta AS oi ON o.order_item_id = oi.order_item_id
          LEFT JOIN wp_posts AS po ON po.ID = o.order_id
          WHERE oi.meta_key='Collection Date'
          AND oi.meta_value IN ('16/01/2016','17/01/2016','18/01/2016','19/01/2016','20/01/2016','21/01/2016')
          ORDER BY po.post_date ASC, o.order_item_id ASC";
  </code></pre>
  
  <p>This query returns all orders which are to be collected within a specific date range.</p>
  
  <pre><code>array (size=3)
    0 =&gt; 
      object(stdClass)[593]
        public 'order_item_id' =&gt; string '19582' (length=5)
        public 'order_item_name' =&gt; string '10 Chocolate Cupcakes' (length=21)
        public 'order_id' =&gt; string '15234' (length=5)
        public 'order_date_placed' =&gt; string '2016-01-14 08:51:31' (length=19)
    1 =&gt; 
      object(stdClass)[592]
        public 'order_item_id' =&gt; string '19600' (length=5)
        public 'order_item_name' =&gt; string '10 Chocolate Cupcakes' (length=21)
        public 'order_id' =&gt; string '15248' (length=5)
        public 'order_date_placed' =&gt; string '2016-01-14 15:43:08' (length=19)
    2 =&gt; 
      object(stdClass)[591]
        public 'order_item_id' =&gt; string '19603' (length=5)
        public 'order_item_name' =&gt; string '10 Chocolate Cupcakes' (length=21)
        public 'order_id' =&gt; string '15250' (length=5)
        public 'order_date_placed' =&gt; string '2016-01-14 15:45:25' (length=19)
  </code></pre>
  
  <p>I now want to pass an additional criteria that will also limit the return data to a specific store location.</p>
  
  <p>I have tried adding the following to the query but this returns null. </p>
  
  <pre><code>WHERE oi.meta_key = 'Pickup Location' 
  AND oi.meta_value LIKE '%Address 1%'
  </code></pre>
  
  <p>Only records which are true for both criteria must return. </p>
  
  <p>I do battle to understand why the meta table in wordpress/woocommerce are set up the way they are with so many redundant/duplicate entries. </p>
  
  <p>I'm not sure whether the developer should have used a raw SQL query or whether there is a better solution for this problem.</p>
  
  <p>Any help is much appreciated. </p>