简体   繁体   中英

Getting order items list in custom php class woocommerce

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

The solution;

$items = $order->get_items();

    foreach ($items as $item ) :
        var_dump($item);
endforeach;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM