How do I get specific key and its value from object?
Example I have output of my query:
"attribute_summary":"Color: Red", "meta_data":[ { "id":5858, "key":"_number_field", "value":"60,20" }, { "id":6275, "key":"_mootmed", "value":"278 x 138 x 80 mm" }, { "id":6276, "key":"_kulu", "value":"1m2 / 26tk" }, { "id":6277, "key":"_varv_va", "value":"hall" }, { "id":6278, "key":"_alus_al", "value":"8,6 m2 / 224 tk / 1350 kg" }, { "id":6279, "key":"_alus_mo", "value":"1200 x 1200 mm" } ]
And I know if I query like this $product->attribute_summary;
I can get data Color: Red
But How do I get data of meta_data
? Like need to get key _alus_al
and its value displayed.
Advertisement
Answer
If you’re talking WooCommerce here. The way to get the specific meta value from the $product
Object is simply.
add_action('your_action', function(){ global $product; $meta_data = $product->get_meta('your_meta_key')); });
see https://woocommerce.github.io/code-reference/classes/WC-Data.html#method_get_meta for reference.