-1

I have woocommrece order detail array which had protective element so when like normal array you can't access them via their key .This array is result of the plugin file code which i have purchased. I have customize this code so many time but the protective array do not let me access into it. Any idea

Array
(
    [1251] => WC_Order_Item_Product Object
        (
            [extra_data:protected] => Array
                (
                    [product_id] => 0
                    [variation_id] => 0
                    [quantity] => 1
                    [tax_class] => 
                    [subtotal] => 0
                    [subtotal_tax] => 0
                    [total] => 0
                    [total_tax] => 0
                    [taxes] => Array
                        (
                            [subtotal] => Array
                                (
                                )

                            [total] => Array
                                (
                                )

                        )

                )

            [data:protected] => Array
                (
                    [order_id] => 2040
                    [name] => Vanilla Pastries
                    [product_id] => 776
                    [variation_id] => 0
                    [quantity] => 5
                    [tax_class] => gst_18
                    [subtotal] => 296.6
                    [subtotal_tax] => 53.388
                    [total] => 296.6
                    [total_tax] => 53.388
                    [taxes] => Array
                        (
                            [total] => Array
                                (
                                    [5] => 26.694
                                    [10] => 26.694
                                )

                            [subtotal] => Array
                                (
                                    [5] => 26.694
                                    [10] => 26.694
                                )

                        )

                )

            [cache_group:protected] => order-items
            [meta_type:protected] => order_item
            [object_type:protected] => order_item
            [id:protected] => 1251
            [changes:protected] => Array
                (
                )

            [object_read:protected] => 1
            [default_data:protected] => Array
                (
                    [order_id] => 0
                    [name] => 
                    [product_id] => 0
                    [variation_id] => 0
                    [quantity] => 1
                    [tax_class] => 
                    [subtotal] => 0
                    [subtotal_tax] => 0
                    [total] => 0
                    [total_tax] => 0
                    [taxes] => Array
                        (
                            [subtotal] => Array
                                (
                                )

                            [total] => Array
                                (
                                )

                        )

                )

            [data_store:protected] => WC_Data_Store Object
                (
                    [instance:WC_Data_Store:private] => WC_Order_Item_Product_Data_Store Object
                        (
                            [internal_meta_keys:protected] => Array
                                (
                                    [0] => _order_id
                                    [1] => _name
                                    [2] => _product_id
                                    [3] => _variation_id
                                    [4] => _quantity
                                    [5] => _tax_class
                                    [6] => _subtotal
                                    [7] => _subtotal_tax
                                    [8] => _total
                                    [9] => _total_tax
                                    [10] => _taxes
                                    [11] => _product_id
                                    [12] => _variation_id
                                    [13] => _qty
                                    [14] => _tax_class
                                    [15] => _line_subtotal
                                    [16] => _line_subtotal_tax
                                    [17] => _line_total
                                    [18] => _line_tax
                                    [19] => _line_tax_data
                                )

                            [meta_type:protected] => order_item
                            [object_id_field_for_meta:protected] => order_item_id
                        )

                    [stores:WC_Data_Store:private] => Array
                        (
                            [coupon] => WC_Coupon_Data_Store_CPT
                            [customer] => WC_Customer_Data_Store
                            [customer-download] => WC_Customer_Download_Data_Store
                            [customer-session] => WC_Customer_Data_Store_Session
                            [order] => WC_Order_Data_Store_CPT
                            [order-refund] => WC_Order_Refund_Data_Store_CPT
                            [order-item] => WC_Order_Item_Data_Store
                            [order-item-coupon] => WC_Order_Item_Coupon_Data_Store
                            [order-item-fee] => WC_Order_Item_Fee_Data_Store
                            [order-item-product] => WC_Order_Item_Product_Data_Store
                            [order-item-shipping] => WC_Order_Item_Shipping_Data_Store
                            [order-item-tax] => WC_Order_Item_Tax_Data_Store
                            [payment-token] => WC_Payment_Token_Data_Store
                            [product] => WC_Product_Data_Store_CPT
                            [product-grouped] => WC_Product_Grouped_Data_Store_CPT
                            [product-variable] => WC_Product_Variable_Data_Store_CPT
                            [product-variation] => WC_Product_Variation_Data_Store_CPT
                            [shipping-zone] => WC_Shipping_Zone_Data_Store
                        )

                    [current_class_name:WC_Data_Store:private] => WC_Order_Item_Product_Data_Store
                    [object_type:WC_Data_Store:private] => order-item-product
                )

            [meta_data:protected] => Array
                (
                )

        )

)
nithinTa
  • 1,632
  • 2
  • 16
  • 32
Pranav Patel
  • 111
  • 1
  • 4
  • 16

2 Answers2

1

The object you want to access has the type WC_Order_Item_Product. Use its public methods to query it for data or tell it to do something.

This is how OOP works. You don't even need to know how the object properties are named.

axiac
  • 68,258
  • 9
  • 99
  • 134
-1

I guess

global $post;

echo '<pre>';
print_r($post->data);
echo '</pre>';

echo $post->data->order_id;