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
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
Share Improve this question asked Nov 29, 2015 at 23:38 zahidzahid 11 silver badge1 bronze badge 1- 1 What have you tried so far and where are you stuck? Do not expect the work to be done for you. Please update your question with an edit. See How to Ask. – Gabriel Commented Nov 30, 2015 at 4:19
1 Answer
Reset to default 0Add Below Code in Your Theme function.php
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->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 );