How to access custom order item meta data from a meta key in WooCommerce?

There is at least 2 ways to get custom order item meta data from a defined meta key:
1) Since WooCommerce 3 – Using WC_Data method get_meta()
2) The older way – Using wc_get_order_item_meta() WooCommerce function

So your hooked function bs_order_lead_time_data() code will be:

add_action( 'woocommerce_my_account_my_orders_column_order-lead-time', 'bs_order_lead_time_data' );
function bs_order_lead_time_data( $order ) {
    foreach ( $order->get_items('shipping') as $item_id => $item ) {
        // Using WC_Data method get_meta() since WooCommerce 3
        echo $item->get_meta('Lead Time');

        // Or the older way (using always the item Id)
        // echo wc_get_order_item_meta( $item_id , 'Lead Time', true );
    }
}

Code goes in functions.php file of your active child theme (or active theme). It should better work.

Leave a Comment