最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Woocommerce - Display product category of product in Orders page

programmeradmin4浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

Add 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 );
发布评论

评论列表(0)

  1. 暂无评论