【问题标题】:Woocommerce WC_Order::get_items() not returning correct informationWoocommerce WC_Order::get_items() 未返回正确信息
【发布时间】:2015-02-25 04:50:04
【问题描述】:

我不知道我做错了还是 woocommerce 中的一些错误,但我无法按预期通过 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) ""
}

【问题讨论】:

  • 如果你 var_dump($order); 会带来什么?
  • 谢谢你的快速回复,我已经添加了上面的信息
  • var_dump($order);中的信息对吗?
  • 还有一点,没有user_id,所以你不能使用$order->user_id
  • 相同的代码在我的机器上运行良好。所以你需要做一点调试,否则你可以使用$orders的产品ID来提取相关信息。

标签: php wordpress woocommerce


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-10-06
    • 2016-07-23
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    相关资源
    最近更新 更多