Retrieve custom order item meta data values in Woocommerce 3
Using your custom order item meta data in woocommerce_payment_complete action hook (or in any other hook where you can get the order ID or the order object):
add_action( 'woocommerce_payment_complete', 'on_action_payment_complete', 10, 1 );function on_action_payment_complete( $order_id ) { // Get an instance of the WC_Order Object $order = wc_get_order( $order_id ); // Loop through order items foreach( $order->get_items() as $item_id => $item ){ $servicelevel = $item->get_meta('Service Level'); $servicecode = $item->get_meta('Your Reference'); $serviceprice = $item->get_meta('Sell Price'); $chargeweight = $item->get_meta('Charge Weight'); }}
Code goes in function.php file of your active child theme (or active theme). It should works. The code inside the hook is tested and really works.