WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end

Since this isn’t getting much action I’ll put our band-aid fix as the current solution.

Problem 1 Solution
The added item meta data shows on the order confirmation page and does not show on the confirmation email. We solved this by utilizing the woocommerce_order_item_meta_end hook to add the extra item meta.

Problem 2 Solution
Adding the item meta data via woocommerce_order_item_meta_end to the confirmation
email also adds it to the confirmation page (visibly duplicating it). We solved this by adding an if statement suggested by @LoicTheAztec here.

add_action('woocommerce_order_item_meta_end', 'email_confirmation_display_order_items', 10, 4);

function email_confirmation_display_order_items($item_id, $item, $order, $plain_text) {

    // Only on emails notifications
    if( ! (is_admin() || is_wc_endpoint_url() )) {
        echo '<div>Voucher Code: '. wc_get_order_item_meta( $item_id, 'Voucher Code') .'</div>';
    }
}

Resources
email confirmation hook visual guide
wc_get_order_item_meta docs
Filter out unwanted order item meta data from Woocommerce email notifications

Leave a Comment