Search code examples
wordpresswoocommerce

Woocommerce - Display product category of product in Orders page


I need to show the product category of product in admin Orders page when a customer make a purchase.Appreciate if any one can help. :) screen shot attached where in need to display product category of product in Orders page. Thanks admin Order page


Solution

  • I'd use get_the_term_list() and add it to the appropriate hook. You can always find an appropriate hook by searching through the WooCommerce code for some CSS/HTML markup. In this case the <td class="name"> tag had a data-sort-value data attribute. You can usually assume that those aren't going to appear everywhere and aren't dynamically generated, so you can use a decent text editor to search the whole WooCommerce folder. That revealed a woocommerce_before_order_itemmeta hook.

    Add this to your theme's functions.php or preferably a site-specific plugin.

    add_action( 'woocommerce_before_order_itemmeta', 'so_before_order_itemmeta', 10, 3 );
    function so_before_order_itemmeta( $item_id, $item, $_product ){
        echo get_the_term_list( $_product->id, 'product_cat', __( 'Categories:', 'textdomain' ), ',', '' ); 
    }