'Woocommerce display orders by custom item meta

I'm trying to display woocommerce orders if they match a key-value pair of an item meta that is part of that order. It's not an order meta but an order item meta.

$orders = wc_get_orders(array(
    'limit' => -1,
    'type'=> 'shop_order',
    'meta_query' => array(
      array(
        'key' => 'agent_name',
        'value' => 'Maribel Z Mercado',
        'compare' => 'LIKE'
      )
    )
));

This code displays all the orders and seam not to filter out anything. Is there a built in solution for this...?

This might be helpful, this is how I get the meta information.

foreach ($order->get_items() as $item_id => $item) {
    $agent_name = wc_get_order_item_meta($item_id, 'agent_name');
}

So if there is a way to get all the order that have item_meta matching the args that would be super helpful.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source