0

I call $order = new WC_Order(52); and I get a correct order object but the Items array is empty.

I 've tried select * from wp_woocommerce_order_items where order_id=52; and I got the line item.

Any ideas whats going wrong ?

I am using WooCommerce 3.4.3.

2

To fetch the order items you can use the method

get_items()

I am doing something similar to you and i am doing it like this

$order = wc_get_order($order_id);
$line_items = $order->get_items();

In WooCommerce 3.0, CRUD objects were added so all the data can be accessed using getters and set using setters. Line items are the same so when you have your line items you should loop them and access the data using getters.

For more information about the available getters and setters for these objects you can use this for reference https://docs.woocommerce.com/wp-content/images/wc-apidocs/class-WC_Order.html for the order object and for the product line items you can check https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item_Product.html

Hope this helps!

  • than you very much indeed – Develope Cruz Jun 26 '18 at 15:38
  • No problem @DevelopeCruz. Please accept the answer if it helped you. – Alex Uleberg Jun 27 '18 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.