4

I need to get the value of ntva from this Object but I can't figure out how to do it.

Meta_data Object ( [current_data:protected] => Array ( [id] => 99769 [key] => ntva [value] => SRTTE ) [data:protected] => Array ( [id] => 99769 [key] => ntva [value] => SRTTE ) );

Foreach ($data->current_data as $key => $value){ 
echo $key.', value'.$value.'<br/>';
}

This foreach does not show me anything.

This object comes from WooCommerce (e-commerce wordpress plugin) ORDER data array. I need the ntva value to display it in PDF invoice.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Houx
  • 265
  • 4
  • 5
  • 13

1 Answers1

5

Looking at the source, WC_Meta_Data has a getter __get, so you will be able to access it like:

$data->key which will output ntva

Or use the get_data() method:

foreach ($data->get_data() as $key => $value){ 
    echo $key.', value'.$value.'<br/>';
}
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
  • 2
    Thank you very much, i have what i need. And the joke is that i always use the method get_data(), shame on me – Houx Mar 24 '18 at 00:59