In this example, We have shared how to get the metadata of an order item in WooCommerce? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // Get the $order object from an ID (if needed only) $order = wc_get_order( $order_id); // Loop through order line items foreach( $order->get_items() as $item ){ // get order item data (in an unprotected array) $item_data = $item->get_data(); // get order item meta data (in an unprotected array) $item_meta_data = $item->get_meta_data(); // get only additional meta data (formatted in an unprotected array) $formatted_meta_data = $item->get_formatted_meta_data(); // Display the raw outputs (for testing) echo '<pre>'; print_r($item_meta_data); echo ' |
1 | '; print_r($formatted_meta_data); echo ' |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.