I am working on a plugin at the moment for Woocommerce.
Right now, I am a little stuck on something, and that is how to get all orders.
This is my code so far:
global $woocommerce;
global $post;
$order = new WC_Order(102249);
$_order = $order->get_items();
foreach($_order as $order_product_detail){
echo "<b>Product ID:</b> ".$order_product_detail['product_id']."<br>";
echo "<b>Product Name:</b> ".$order_product_detail['name']."<br><br>";
}
This works. But I need all orders. Now I only get order no. 102249. I have tried to use$order = new WC_Order($post->ID);
But this gives me a notice: Notice: Trying to get property of non-object
I assume this has to do that WordPress has not loaded the global $post
yet.
So how can I get all orders. And how can I wait for WordPress to have fully loaded?
I have looked at the codex of WordPress and Woocommerce, this did not help me unfortunately.