Friday, July 8, 2022
HomeWordPress Developmenttype - Woocommerce Admin Order sorting not working

type – Woocommerce Admin Order sorting not working


I’ve created a customized column referred to as “Quantity” to rely the whole variety of accomplished order for every order. Column added efficiently, worth additionally being fetched with none concern. I registered the column as sortable and added an motion to type the column, however it isn’t working. The column to be sorted is in numeric. Beneath is my code

   add_filter('manage_edit-shop_order_columns', 'misha_order_items_column_volume' );
perform misha_order_items_column_volume( $order_columns ) {
    $order_columns['order_products_volume'] = "Quantity";
    return $order_columns;
}

add_action( 'manage_shop_order_posts_custom_column' , 'misha_order_items_column_cnt_volume' );
perform misha_order_items_column_cnt_volume( $colname ) {
    international $the_order; // the worldwide order object
    if( $colname == 'order_products_volume' ) {
        $order_items = $the_order->get_id();
        $order = new WC_Order( $order_items );
        $first_name=$order->get_billing_first_name();
        $last_name=$order->get_billing_last_name();
        $args = array(
            'billing_first_name' => $first_name,
            'billing_last_name' => $last_name,
            'post_status' => 'accomplished',
            'post_type' => 'shop_order',
            'return' => 'ids',
            'numberposts' => -1
        );  
        echo intval(rely(wc_get_orders( $args )));
    }
}


perform register_sortable_columns( $columns ) {
    $order_columns['order_products_volume'] = array('order_products_volume','true');
    return $order_columns;
}
add_filter( 'manage_edit-shop_order_sortable_columns', 'register_sortable_columns' ); 

//This isn't working
add_action( 'pre_get_posts', 'closing_column_orderby' );  
perform closing_column_orderby( $question ) {  
    if( ! is_admin() )  
        return;  

    $orderby = $query->get( 'orderby');  
    if( 'order_products_volume' == $orderby ) {  
        $query->set('meta_key','order_products_volume'); 
        $query->set('meta_type','NUMBER');
        $query->set('orderby','meta_value_num');  
    }  
} 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments