I’m struggling to get specific data from wc_get_orders()
.
Here is the code:
$args = array(
'numberposts' => - 1,
'orderby' => 'date',
'order' => 'DESC',
'customer_id' => get_current_user_id(),
);
$orders = wc_get_orders( $args );
echo '<pre>', var_dump( $orders ), '</pre>';
Here is the part of the object:
["meta_data":protected]=>
array(4) {
[0]=>
object(WC_Meta_Data)#3544 (2) {
["current_data":protected]=>
array(3) {
["id"]=>
int(1135)
["key"]=>
string(13) "is_vat_exempt"
["value"]=>
string(2) "no"
}
["data":protected]=>
array(3) {
["id"]=>
int(1135)
["key"]=>
string(13) "is_vat_exempt"
["value"]=>
string(2) "no"
}
}
[1]=>
object(WC_Meta_Data)#3545 (2) {
["current_data":protected]=>
array(3) {
["id"]=>
int(1136)
["key"]=>
string(13) "tip_korisnika"
["value"]=>
string(13) "Fizičko lice"
}
["data":protected]=>
array(3) {
["id"]=>
int(1136)
["key"]=>
string(13) "tip_korisnika"
["value"]=>
string(13) "Fizičko lice"
}
}
[2]=>
object(WC_Meta_Data)#3546 (2) {
["current_data":protected]=>
array(3) {
["id"]=>
int(1137)
["key"]=>
string(12) "fs4e_methods"
["value"]=>
string(5) "obuka"
}
["data":protected]=>
array(3) {
["id"]=>
int(1137)
["key"]=>
string(12) "fs4e_methods"
["value"]=>
string(5) "obuka"
}
}
[3]=>
I’m trying to get the value of tip_korisinka
, which is inside WC_Meta_Data
that seems to be protected. Check this screenshot: https://prnt.sc/CI-UfqEkuuag
This is one of the solutions without success that I have tried so far:
foreach ( $orders as $key => $value ) {
echo $key->$value['tip_korisnika'];
}
Any help would be appreciated.