Php 在Woocommerce中获取订单项目名称

Php 在Woocommerce中获取订单项目名称,php,woocommerce,orders,Php,Woocommerce,Orders,所以我有一个变量,如果我var_转储这个变量,我会得到一个大数组。我试图得到以下信息: ["name"]=> string(26) "Online marketing Duitsland" 整个数组结果如下所示: array(1) { [33]=> object(WC_Order_Item_Product)#9730 (11) { ["extra_data":protected]=> array(9) { ["product_id"]=>

所以我有一个变量,如果我var_转储这个变量,我会得到一个大数组。我试图得到以下信息:

["name"]=> string(26) "Online marketing Duitsland" 
整个数组结果如下所示:

array(1) { 
  [33]=> object(WC_Order_Item_Product)#9730 (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(12291) 
      ["name"]=> string(26) "Online marketing Duitsland" 
      ["product_id"]=> int(11927) 
      ["variation_id"]=> int(0) 
      ["quantity"]=> int(1) 
      ["tax_class"]=> string(0) "" 
      ["subtotal"]=> string(4) "3700" 
      ["subtotal_tax"]=> string(1) "0" 
      ["total"]=> string(4) "3700" 
      ["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(33) 
    ["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)#9723 (4) { 
      ["instance":"WC_Data_Store":private]=> object(WC_Order_Item_Product_Data_Store)#9722 (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(20) { 
        ["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-download-log"]=> string(35) "WC_Customer_Download_Log_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" 
        ["webhook"]=> string(21) "WC_Webhook_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(0) { } 
  } 
} 
如何获取该特定部分?

使用get\u name方法

$var[33]->get_name();
使用get_name方法

$var[33]->get_name();
或者尝试:-

echo $arr[33]->data->name;
或者尝试:-

 $arr = (Array)$arr;//cast the object as an Array
 echo $arr[33]["\0*\0" . 'data']['name'];
要获得更多支持和理解:-

请尝试:-

echo $arr[33]->data->name;
或者尝试:-

 $arr = (Array)$arr;//cast the object as an Array
 echo $arr[33]["\0*\0" . 'data']['name'];

有关更多支持和理解:-

它将不起作用,数据受保护属性它将不起作用,数据受保护属性请参阅此解决方案在Woocommerce 3中获取订单项目和WC_订单项目产品首先,您需要使用foreach循环,在其内部之后,您可以使用Get_name方法,如:foreach$Order->Get_items as$Item{echo$item->get_name;}…或者如果您只有一个订单项:$items=$order->get_items;$item=reset$items;echo$item->get_name;@LoicTheAztec非常感谢这对我的帮助。在Woocommerce 3中查看此解决方案get order items和WC_order_item_Product首先,您需要使用foreach循环,在其内部可以使用get_name方法,如:foreach$order->获取商品为$item{echo$item->get_name;}…或者如果您只有一个订单商品:$items=$order->get_items;$item=reset$items;echo$item->get_name;@LoicTheAztec非常感谢这帮了我的忙。var_dump$order->get_items[33]->get_name我试过这个,它在我休息前就起作用了..当我回来时,我有一个错误。我很困惑这可能是因为它不再是33了。你从哪里获取这个变量?我最终以@LoicTheAztec的方式完成了它。谢谢你的帮助,非常感谢。var_dump$order->get_items[33]->我试过这个,它在我休息前起作用。当我回来时,我有一个错误。我很困惑这可能是因为它不再是33号了。你从哪里获取这个变量?我最终以@LoicTheAztec的方式完成了它。谢谢你的帮助,非常感谢。