Add the following PHP code to your child theme functions.php file.
<?php //to display the category on the admin order page function action_woocommerce_admin_order_item_headers( ) { ?> <th class="item sortable" colspan="2" data-sort="string-ins"><?php _e( 'Item category', 'woocommerce' ); ?></th> <?php } // define the woocommerce_admin_order_item_values callback function action_woocommerce_admin_order_item_values( $_product, $item, $item_id ) { ?> <td class="name" colspan="2" > <?php $termsp = get_the_terms( $_product->get_id(), 'product_cat' ); if(!empty($termsp)){ foreach ($termsp as $term) { $_categoryid = $term->term_id; if( $term = get_term_by( 'id', $_categoryid, 'product_cat' ) ){ echo $term->name .', '; } } } ?> </td> <?php }; // add the action add_action( 'woocommerce_admin_order_item_values', 'action_woocommerce_admin_order_item_values', 10, 3 ); add_action( 'woocommerce_admin_order_item_headers', 'action_woocommerce_admin_order_item_headers', 10, 0 ); ?>
0 Comments