Wooccommerce WC_Order::get_items()未返回正确的信息


Woocommerce WC_Order::get_items() not returning correct information

我不知道我做这件事的方式是否错误,或者这是wooccommerce中的某个错误,但我无法像预期的那样通过WC_Order::get_items()函数获取产品信息

我的代码是:

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

我得到的回复是:

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

如果我做错了什么,请告诉我,正如我在Wordpress管理面板中看到的,与此order_id 相对应的完整信息

var_dump($order);的输出为:

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) ""
}

哦!这是我的错误。我从一个自定义函数调用了这段代码来测试它,甚至在wooccommerce初始化之前,所以代码在中不起作用