wordpress - Get quantity of items in woocommerce in admin panel -


i using ni invoice plugin shows orders when select date range. want 1 more field in order quantity. unable quantity of products bought. code generates table goes this:

                <?php             foreach($order_data $k => $v){                 $order_total += isset($v->order_total)?$v->order_total:0;             ?>                 <tr>                     <td> <?php echo $v->order_id;?> </td>                     <td> <?php echo $v->order_date;?> </td>                     <td> <?php echo $v->***?> </td>                      <td> <?php echo ucfirst ( str_replace("wc-","", $v->order_status));?> </td>                    </tr>                <?php }?> 

in 3rd td> tag want display quantity of products purchased. how fetch that?
$order_data variable s follows $order_data = $this->get_order_data(); , get_order_data() function follows:

function get_order_data()     {         $order_query = $this->get_order_query("default");           if(count($order_query)> 0){             foreach($order_query $k => $v){                  /*order data*/                 $order_id =$v->order_id;                 $order_detail = $this->get_order_detail($order_id);                 foreach($order_detail $dkey => $dvalue)                 {                         $order_query[$k]->$dkey =$dvalue;                  }             }         }         else         {             echo "no record found";         }         return $order_query;     } 


get_order_detail function goes this:

function get_order_detail($order_id)     {         $order_detail   = get_post_meta($order_id);         $order_detail_array = array();         foreach($order_detail $k => $v)         {             $k =substr($k,1);             $order_detail_array[$k] =$v[0];         }         return  $order_detail_array;     } 

in plugin file name 'ni-order-list.php' replace code file code.its working.

[![<?php  if ( ! defined( 'abspath' ) ) { exit;} include_once('ni-function.php');  if( !class_exists( 'ni_order_list' ) ) {     class ni_order_list extends ni_function{         public function __construct(){          }         public function page_init(){         ?>         <form id="ni_frm_order_export" class="ni-frm-order-export" name="ni_frm_order_export" action="" method="post">             <table>                 <tr>                     <td>select order</td>                     <td><select name="select_order" id="select_order">                     <option value="today">today</option>                     <option value="yesterday">yesterday</option>                     <option value="last_7_days">last 7 days</option>                         <option value="last_30_days">last 30 days</option>                     <option value="this_year">this year</option>                     </select>                     </td>                 </tr>                 <tr>                     <td colspan="2" style="text-align:right"><input type="submit" value="search" id="searchorder" /></td>                 </tr>             </table>             <input type="hidden" name="action" value="ni_action" />             <input type="hidden" name="ni_action_ajax" value="ni_woocommerce_invoice" />         </form>         <div class="ajax_content"></div>         <?php          }         function get_order_query($type="default"){             global $wpdb;                $today = date("y-m-d");             $select_order = $this->get_request("select_order");              $query = "select                  posts.id order_id                 ,post_status order_status                 , date_format( posts.post_date, '%y-%m-%d') order_date                  {$wpdb->prefix}posts posts                                                    posts.post_type ='shop_order'                          ";                  switch ($select_order) {                     case "today":                         $query .= " ,   date_format( posts.post_date, '%y-%m-%d') between '{$today}' , '{$today}'";                         break;                     case "yesterday":                         $query .= " ,  date_format( posts.post_date, '%y-%m-%d') = date_format( date_sub(curdate(), interval 1 day), '%y-%m-%d')";                         break;                     case "last_7_days":                         $query .= " ,  date_format( posts.post_date, '%y-%m-%d') between date_format(date_sub(curdate(), interval 7 day), '%y-%m-%d') ,   '{$today}' ";                         break;                     case "last_30_days":                             $query .= " ,  date_format( posts.post_date, '%y-%m-%d') between date_format(date_sub(curdate(), interval 30 day), '%y-%m-%d') ,   '{$today}' ";                         break;                       case "this_year":                         $query .= " ,  year(date_format( posts.post_date, '%y-%m-%d')) = year(date_format(curdate(), '%y-%m-%d'))";                                    break;                           default:                         $query .= " ,   date_format( posts.post_date, '%y-%m-%d') between '{$today}' , '{$today}'";                 }             $query .= "order posts.post_date desc";             if ($type=="array_a") /*export*/             $results = $wpdb->get_results( $query, array_a );          if($type=="default") /*default*/             $results = $wpdb->get_results( $query);           if($type=="count") /*count only*/               $results = $wpdb->get_var($query);                   //echo $query;             echo mysql_error();         //  $this->print_data($results);             return $results;             }         /*get_order_list*/         function get_order_list()         {             $this->get_order_grid();               }         function get_order_data()         {             $order_query = $this->get_order_query("default");               if(count($order_query)> 0){                 foreach($order_query $k => $v){                      /*order data*/                     $order_id =$v->order_id;                     $order_detail = $this->get_order_detail($order_id);                     foreach($order_detail $dkey => $dvalue)                     {                             $order_query\[$k\]->$dkey =$dvalue;                      }                 }             }             else             {                 echo "no record found";             }             return $order_query;         }         function get_order_grid()         {             $order_total = 0;             $order_data = $this->get_order_data();              //$this->print_data ($order_data);              if(count($order_data)> 0)             {                 ?>                <div class="data-table">                 <table>                     <tr>                         <th>#id</th>                         <th>order date</th>                         <th>billing first name</th>                          <th>billing email</th>                          <th>billing country</th>                          <th>status</th>                         <th>order qty</th>                         <th>order currency</th>                         <th>order total</th>                         <th>invoice</th>                     </tr>                  <?php                 foreach($order_data $k => $v){                     $order_total += isset($v->order_total)?$v->order_total:0;                      $order = new wc_order( $v->order_id );                     $itemdetails=$order->get_items();                     $itemmeta_temp=array_column($itemdetails, 'item_meta');                     //print_r(array_column($itemmeta_temp, '_qty')\[0\]\[0\]);                     //print_r($itemdetails);                   ?>                      <tr>                         <td> <?php echo $v->order_id;?> </td>                         <td> <?php echo $v->order_date;?> </td>                         <td> <?php echo $v->billing_first_name;?> </td>                         <td> <?php echo $v->billing_email;?> </td>                         <td> <?php echo $this->get_country_name($v->billing_country);?> </td>                         <td> <?php echo ucfirst ( str_replace("wc-","", $v->order_status));?> </td>                         <td> <?php echo array_column($itemmeta_temp, '_qty')\[0\]\[0\];?> </td>                         <td> <?php echo $v->order_currency;?> </td>                         <td style="text-align:right"> <?php echo woocommerce_price($v->order_total);?> </td>                          <td> <a href="<?php echo admin_url("admin.php?page=ni-woocommerce-invoice")."&ni-order-invoice=". $v->order_id  ; ?>">invoice</a></td>                     </tr>                    <?php }?>                 </table>                 <div style="text-align:right; margin-top:10px">                     <?php  echo woocommerce_price($order_total); ?>                 </div>                 <?php                  //$this->print_data(    $order_data );             }         }         /*get order header information*/         function get_order_detail($order_id)         {             $order_detail   = get_post_meta($order_id);             $order_detail_array = array();             foreach($order_detail $k => $v)             {                 $k =substr($k,1);                 $order_detail_array\[$k\] =$v\[0\];             }             return  $order_detail_array;         }     } } ?>][1]][1] 

Comments