I am trying to filter WC orders on customer order dashboard page using woocommerce_my_account_my_orders_query filter. and Order by date, title etc are working fine for me but when i try to filter orders by custom meta keys and values then it’s not returning me correct result.

add_filter( 'woocommerce_my_account_my_orders_query', 'af_filter_orders', 10, 1 );

function af_filter_orders( $orders ) { 

    $orders = array(
     'limit'       => -1,
     'offset'      => null,
     'page'        => 1,
     'meta_key' => 'custom_meta_key', //meta type is plain string and i need results alphabetically.
     'orderby' => 'meta_value', //meta_value_num
     'order' => 'DESC', //ASC
     'customer' => get_current_user_id(),  
     'paginate' => true
    );
    return $orders;

} 

I am on WC v2.6. have not tested on 3x yet. and i need it working with 2.6

Read more here: Unable to sort Orders on customer order page by meta value


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: