admin管理员组文章数量:1125605
I've created a class that extend WP_List_table to manage WC orders in a plugin admin menu.
public static function get_orders( $per_page = 5, $page_number = 1 ) {
global $wpdb;
$query = new WC_Order_Query( array(
'limit' => $per_page,
) );
if ( ! empty( $_REQUEST['orderby'] ) ) {
$order_by = (isset($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_keys(self::get_sortable_columns()))) ? $_REQUEST['orderby'] : 'date';
$query->set( 'orderby', $order_by );
}
//$sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
$orders = $query->get_orders();
return $orders;
}
And the sortable columns definition :
public function get_sortable_columns() {
$sortable_columns = array(
'order_modified_date' => array( 'modfied', true ) ,
'order_customer' => array( 'order_organization', true ) ,
'order_organization' => array( 'order_organization', true ) ,
'order_total' => array( 'order_total', false ) ,
'date' => array( 'date', false )
);
return $sortable_columns;
}
Also the prepare_items function as follow :
public function prepare_items() {
$this->_column_headers = $this->get_column_info();
/** Process bulk action */
$this->process_bulk_action();
$per_page = $this->get_items_per_page( 'customers_per_page', 5 );
$current_page = $this->get_pagenum();
/** get data from get_orders **/
$orders = self::get_orders( $per_page, $current_page );
$data = array();
foreach($orders as $order){
$data[] = array(
'ID' => $order->get_id() ,
'date' => $order->get_date_created()->date('Y-m-d'),
'order_customer' => $order->get_user_id(),
'order_modified_date' => $order->get_date_modified(),
'order_organization' => 'null',
'order_product' => 'get_order_product',
'order_payment_method' => $order->get_payment_method_title(),
'order_status' => $order->get_status() ,
'order_total' => $order->get_total(),
);
}
$total_items = count( $data );
$this->set_pagination_args( [
'total_items' => $total_items,
'per_page' => $per_page
] );
$this->items = $data;
}
I tried several approach but my column 'date' sorting doesn't work at all.
Any ideas what I'm doing wrong?
Thanks
本文标签: plugin developmentWPListTable sortable column with WCOrderQuery doesn39t work
版权声明:本文标题:plugin development - WP_List_Table sortable column with WC_Order_Query doesn't work 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736650807a1946137.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论