I’ve tried many different ways but none of them seem to work for me. I’ve tried doing a WP_Query like this:
$query = new WP_Query([
'post_type' => 'shop_order',
'post_status' => 'publish',
'posts_per_page' => '-1',
'year' => date("Y"),
'monthnum' => date("m"),
'w' => date("W"),
]);
foreach ($query->posts as $order) {
$product = $order->get_product_from_item($order->ID);
echo $product->get_title();
// Now I need the variation name and the amount of times the clientes orders this
}
Basically, I want to get the orders of an item showing the variation and the amount of times this was ordered in the current week.
Something like this:
[product name] | [variation] | [total amount ordered by all customers]
Does anyone has an idea of what I need to do in order to achieve this?