Woocommerce WC_Order::get_items() not returning correct information

I don’t know if I am doing it the wrong way or is it some bug in woocommerce but I can’t get product information through the WC_Order::get_items() function as expected

My code is :

Read More
 $order = new WC_Order($order_id); //$order_id = 114
 $user_id = $order->user_id;
 print_r($order->get_items());
 die();

Response I am getting is :

Array
(
    [3373] => Array
        (
            [name] => CLASSIC CLEANSE
            [type] => line_item
            [item_meta] => 
        )

)

Please tell me if I am doing something wrong, as I can see in WordPress Admin panel complete information corresponding to this order_id

output of var_dump($order); is :

object(WC_Order)#2381 (14) {
  ["id"]=>
  int(5466)
  ["post"]=>
  object(WP_Post)#2384 (24) {
    ["ID"]=>
    int(5466)
    ["post_author"]=>
    string(1) "1"
    ["post_date"]=>
    string(19) "2015-02-23 14:15:42"
    ["post_date_gmt"]=>
    string(19) "2015-02-23 13:15:42"
    ["post_content"]=>
    string(0) ""
    ["post_title"]=>
    string(41) "Order – Februar 23, 2015 @ 02:15 PM"
    ["post_excerpt"]=>
    string(0) ""
    ["post_status"]=>
    string(10) "wc-on-hold"
    ["comment_status"]=>
    string(6) "closed"
    ["ping_status"]=>
    string(6) "closed"
    ["post_password"]=>
    string(19) "order_54eb27feb27c7"
    ["post_name"]=>
    string(32) "bestellung-23-feb-2015-um-1315-2"
    ["to_ping"]=>
    string(0) ""
    ["pinged"]=>
    string(0) ""
    ["post_modified"]=>
    string(19) "2015-02-23 14:15:42"
    ["post_modified_gmt"]=>
    string(19) "2015-02-23 13:15:42"
    ["post_content_filtered"]=>
    string(0) ""
    ["post_parent"]=>
    int(0)
    ["guid"]=>
    string(56) "https:/my_site_url/?post_type=shop_order&p=5466"
    ["menu_order"]=>
    int(0)
    ["post_type"]=>
    string(10) "shop_order"
    ["post_mime_type"]=>
    string(0) ""
    ["comment_count"]=>
    string(1) "1"
    ["filter"]=>
    string(3) "raw"
  }
  ["order_type"]=>
  string(6) "simple"
  ["order_date"]=>
  string(19) "2015-02-23 14:15:42"
  ["modified_date"]=>
  string(19) "2015-02-23 14:15:42"
  ["customer_message"]=>
  string(0) ""
  ["customer_note"]=>
  string(0) ""
  ["post_status"]=>
  string(10) "wc-on-hold"
  ["prices_include_tax"]=>
  bool(true)
  ["tax_display_cart"]=>
  string(4) "incl"
  ["display_totals_ex_tax"]=>
  bool(false)
  ["display_cart_ex_tax"]=>
  bool(false)
  ["formatted_billing_address":protected]=>
  string(0) ""
  ["formatted_shipping_address":protected]=>
  string(0) ""
}

Related posts

Leave a Reply

1 comment

  1. Oh! It was my mistake.
    I was calling this code from a custom function to test it, even before the woocommerce was initialized, so the code was not working