Reputation: 3169
In my custom class I would like to print the items ordered by the customer. What is the right way of doing this in a custom class with wooCommerce?
Example of my code;
$args = array(
'post_type' => 'shop_order',
'post_status' => 'wc-processing',
'meta_key' => '_customer_user',
'posts_per_page' => '-1',
);
$my_query = new WP_Query($args);
$customer_orders = $my_query->posts;
# Loop through orders
foreach ($customer_orders as $customer_order) :
$order = new WC_Order($customer_order->id);
$order->populate($customer_order);
$this->woOrders[] = (array) $order;
# User billing address
$this->billingAddress = $order->get_formatted_billing_address();
echo $this->billingAddress;
# User shipping address
$this->shippingAddress = $order->get_formatted_shipping_address();
echo $this->shippingAddress .'<br>';
endforeach;
Thanks
Upvotes: 0
Views: 1496
Reputation: 3169
The solution;
$items = $order->get_items();
foreach ($items as $item ) :
var_dump($item);
endforeach;
Upvotes: 2