w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to sort orders based on orders meta value in Woocommerce / Wordpress

You need to did more deeper and you certainly need some php knowledge to achieve this. In a project I had to develop something similar, I'm sharing the code but you need to edit as per your requirement.

// this action brings up a dropdown select box over the posts
list in the dashboard
add_action('restrict_manage_posts','my_custom_restrict_manage_posts');

function my_custom_restrict_manage_posts() {

    if( current_user_can('manage_options') ){

        global $typenow;
        global $wp_query;
        global $woocommerce;

        if ($typenow=='shop_order') {

            // here you create your own selectbbox
            // you can enqueue js using wc_enqueue_js()

        }

    }
}

function my_custom_orders_by_query( $vars ) {
    global $typenow, $wp_query;

    // check your filter that might come form the previous dropdown
    if ( $typenow == 'shop_order' && isset(
$_GET['select_box_name'] )  ) {

        $meta_key = ''; // your meta key

        $vars['meta_key'] = ''; // your meta value that came from the query
string
        // you might want this because that will show in the url of the
page

        $vars['meta_key'] = ''; // set meta key in the query var
        $vars['meta_value'] = '';       // set meta value in the query var
    }

    return $vars;
}

add_filter( 'request', 'my_custom_orders_by_query' );

This code is the most generic one. you need to customize how you want to setup a dropdown box in the header and how the key and value will reflect in the request filter.

If you require any more assistance feel free to comment.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.