在我的自定义课程中,我想打印客户订购的商品。 使用wooCommerce在自定义类中执行此操作的正确方法是什么?
我的代码示例;
$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;
由于
答案 0 :(得分:2)
解决方案;
$items = $order->get_items();
foreach ($items as $item ) :
var_dump($item);
endforeach;