Display Product Category Names in WooCommerce Order Details

Quick Summary

  • Hook woocommerce_order_item_meta_end to print each item's product_cat names, from wp_get_post_terms(), in customer order details and order emails.
  • A second function on woocommerce_after_order_itemmeta shows category names on the admin order edit screen, skipping shipping and fee rows via is_type line_item.
  • Plain-text order emails may show the br and small tags as text, because the function ignores the hook's plain-text flag argument.

WooCommerce order details list each item’s name, quantity and total, but not the product’s categories. This snippet adds the category names under each order item, both where customers see their order and on the order edit screen in the admin.

Add the code to your child theme’s functions.php or a code snippets plugin. WooCommerce must be active.

PHP
// Display order items product categories (Orders on front end and emails)
add_action( 'woocommerce_order_item_meta_end', 'display_custom_data_in_emails', 10, 4 );
function display_custom_data_in_emails( $item_id, $item, $order, $bool ) {
    // Get the product categories for this item
    $terms = wp_get_post_terms( $item->get_product_id(), 'product_cat', array( 'fields' => 'names' ) );

    // Output a coma separated string of product category names
    echo "<br><small>" . implode(', ', $terms) . "</small>";
}

// Display order items product categories in admin order edit pages
add_action( 'woocommerce_after_order_itemmeta', 'custom_admin_order_itemmeta', 15, 3 );
function custom_admin_order_itemmeta( $item_id, $item, $product ){
    //if( ! is_admin() ) return; // only backend

    // Target order "line items" only to avoid errors
    if( $item->is_type( 'line_item' ) ){
        // Get the product categories for this item
        $terms = wp_get_post_terms( $item->get_product_id(), 'product_cat', array( 'fields' => 'names' ) );

        // Output a coma separated string of product category names
        echo "<br><small>" . implode(', ', $terms) . "</small>";
    }
}

Front end and emails

The first function hooks into woocommerce_order_item_meta_end, which WooCommerce fires after each item’s meta in the customer-facing order details (the order received page and My Account > Orders) and in order emails.

  • $item->get_product_id() returns the product ID. For a variation it’s the parent product, which is where the categories are set.
  • wp_get_post_terms() with 'fields' => 'names' returns just the names of the product_cat terms. The same function can list category names and descriptions on the single product page.
  • implode() joins them with commas, and the result is printed on a new line inside a <small> tag.

The function ignores its fourth argument, which WooCommerce uses to flag plain-text emails, so if you send plain-text emails the <br> and <small> tags may show up as text there.

Admin order edit screen

The second function uses woocommerce_after_order_itemmeta, which runs below each item on the order edit screen. The is_type( 'line_item' ) check skips rows such as shipping and fees: they have no product, and calling get_product_id() on them would cause an error.

To change the look, edit the two echo lines, for example to add a label before the names. Wrapping the names in esc_html() is a good habit.

If your order emails and admin screens need custom details like these, that’s part of my WooCommerce development work.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More