我不知道我是以错误的方式做到这一点还是在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) ""
}
答案 0 :(得分:1)
哦!这是我的错。 即使在初始化woocommerce之前,我也是从自定义函数调用此代码进行测试,因此代码无效