我想打印meta_data的数组大小。以下是项目的对象:
array(1){
[
8
]=>object(WC_Order_Item_Product)#3734(11){
[
"extra_data": protected
]=>array(9){
[
"product_id"
]=>int(0)[
"variation_id"
]=>int(0)[
"quantity"
]=>int(1)[
"tax_class"
]=>string(0)""[
"subtotal"
]=>int(0)[
"subtotal_tax"
]=>int(0)[
"total"
]=>int(0)[
"total_tax"
]=>int(0)[
"taxes"
]=>array(2){
[
"subtotal"
]=>array(0){
}[
"total"
]=>array(0){
}
}
}[
"data": protected
]=>array(11){
[
"order_id"
]=>int(17616)[
"name"
]=>string(10)"Alex check"[
"product_id"
]=>int(17477)[
"variation_id"
]=>int(0)[
"quantity"
]=>int(1)[
"tax_class"
]=>string(0)""[
"subtotal"
]=>float(960)[
"subtotal_tax"
]=>string(1)"0"[
"total"
]=>float(960)[
"total_tax"
]=>string(1)"0"[
"taxes"
]=>array(2){
[
"total"
]=>array(0){
}[
"subtotal"
]=>array(0){
}
}
}[
"cache_group": protected
]=>string(11)"order-items"[
"meta_type": protected
]=>string(10)"order_item"[
"object_type": protected
]=>string(10)"order_item"[
"id": protected
]=>int(8)[
"changes": protected
]=>array(0){
}[
"object_read": protected
]=>bool(true)[
"default_data": protected
]=>array(11){
[
"order_id"
]=>int(0)[
"name"
]=>string(0)""[
"product_id"
]=>int(0)[
"variation_id"
]=>int(0)[
"quantity"
]=>int(1)[
"tax_class"
]=>string(0)""[
"subtotal"
]=>int(0)[
"subtotal_tax"
]=>int(0)[
"total"
]=>int(0)[
"total_tax"
]=>int(0)[
"taxes"
]=>array(2){
[
"subtotal"
]=>array(0){
}[
"total"
]=>array(0){
}
}
}[
"data_store": protected
]=>object(WC_Data_Store)#3736(4){
[
"instance": "WC_Data_Store": private
]=>object(WC_Order_Item_Product_Data_Store)#3737(3){
[
"internal_meta_keys": protected
]=>array(20){
[
0
]=>string(9)"_order_id"[
1
]=>string(5)"_name"[
2
]=>string(11)"_product_id"[
3
]=>string(13)"_variation_id"[
4
]=>string(9)"_quantity"[
5
]=>string(10)"_tax_class"[
6
]=>string(9)"_subtotal"[
7
]=>string(13)"_subtotal_tax"[
8
]=>string(6)"_total"[
9
]=>string(10)"_total_tax"[
10
]=>string(6)"_taxes"[
11
]=>string(11)"_product_id"[
12
]=>string(13)"_variation_id"[
13
]=>string(4)"_qty"[
14
]=>string(10)"_tax_class"[
15
]=>string(14)"_line_subtotal"[
16
]=>string(18)"_line_subtotal_tax"[
17
]=>string(11)"_line_total"[
18
]=>string(9)"_line_tax"[
19
]=>string(14)"_line_tax_data"
}[
"meta_type": protected
]=>string(10)"order_item"[
"object_id_field_for_meta": protected
]=>string(13)"order_item_id"
}[
"stores": "WC_Data_Store": private
]=>array(18){
[
"coupon"
]=>string(24)"WC_Coupon_Data_Store_CPT"[
"customer"
]=>string(22)"WC_Customer_Data_Store"[
"customer-download"
]=>string(31)"WC_Customer_Download_Data_Store"[
"customer-session"
]=>string(30)"WC_Customer_Data_Store_Session"[
"order"
]=>string(23)"WC_Order_Data_Store_CPT"[
"order-refund"
]=>string(30)"WC_Order_Refund_Data_Store_CPT"[
"order-item"
]=>string(24)"WC_Order_Item_Data_Store"[
"order-item-coupon"
]=>string(31)"WC_Order_Item_Coupon_Data_Store"[
"order-item-fee"
]=>string(28)"WC_Order_Item_Fee_Data_Store"[
"order-item-product"
]=>string(32)"WC_Order_Item_Product_Data_Store"[
"order-item-shipping"
]=>string(33)"WC_Order_Item_Shipping_Data_Store"[
"order-item-tax"
]=>string(28)"WC_Order_Item_Tax_Data_Store"[
"payment-token"
]=>string(27)"WC_Payment_Token_Data_Store"[
"product"
]=>string(25)"WC_Product_Data_Store_CPT"[
"product-grouped"
]=>string(33)"WC_Product_Grouped_Data_Store_CPT"[
"product-variable"
]=>string(34)"WC_Product_Variable_Data_Store_CPT"[
"product-variation"
]=>string(35)"WC_Product_Variation_Data_Store_CPT"[
"shipping-zone"
]=>string(27)"WC_Shipping_Zone_Data_Store"
}[
"current_class_name": "WC_Data_Store": private
]=>string(32)"WC_Order_Item_Product_Data_Store"[
"object_type": "WC_Data_Store": private
]=>string(18)"order-item-product"
}[
"meta_data": protected
]=>array(3){
[
0
]=>object(WC_Meta_Data)#3751(2){
[
"current_data": protected
]=>array(3){
[
"id"
]=>int(93)[
"key"
]=>string(130)"pantalone ($890.00)"[
"value"
]=>string(1)"1"
}[
"data": protected
]=>array(3){
[
"id"
]=>int(93)[
"key"
]=>string(130)"pantalone ($890.00)"[
"value"
]=>string(1)"1"
}
}[
1
]=>object(WC_Meta_Data)#3752(2){
[
"current_data": protected
]=>array(3){
[
"id"
]=>int(94)[
"key"
]=>string(125)"Shoes ($40.00)"[
"value"
]=>string(1)"1"
}[
"data": protected
]=>array(3){
[
"id"
]=>int(94)[
"key"
]=>string(125)"Shoes ($40.00)"[
"value"
]=>string(1)"1"
}
}[
2
]=>object(WC_Meta_Data)#3753(2){
[
"current_data": protected
]=>array(3){
[
"id"
]=>int(95)[
"key"
]=>string(123)"Cap ($30.00)"[
"value"
]=>string(1)"1"
}[
"data": protected
]=>array(3){
[
"id"
]=>int(95)[
"key"
]=>string(123)"Cap ($30.00)"[
"value"
]=>string(1)"1"
}
}
}
}
}
请有人帮我弄明白。我试图找出以下功能:
function custom_cnt_items($items) {
$order = wc_get_order( 17616 );
$items = $order->get_items();
$arr = [];
foreach($items as $k => $obj) {
$arr[] = $obj;
}
foreach($arr[0] as $k => $v) {
foreach($v as $a => $b) {
echo $a . $b;
}
}
wp_die();
}
但是不能在Wordpress functions.php文件中工作......
答案 0 :(得分:0)
我无法通过使用对象直接访问meta_data对象属性,因为它受到保护。我必须在特定类中使用一些woocommerce方法来检索数组格式的数据。