How to add custom filter to woocommerce admin orders page

Question

I successfully added new column ‘order_pickup’ to woocommerce orders page:

add_filter( 'manage_edit-shop_order_columns', 'wc_order_pickup_column' );
function wc_order_pickup_column( $columns ) {
    $columns['order_pickup'] = 'Place';
    return $columns;
}

add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_column_order_pickup', 10, 2 );
function custom_shop_order_column_order_pickup( $column, $post_id ) {
    switch ( $column ) {
        case 'order_pickup' :
            echo esc_html( get_post_meta( $post_id, 'order_pickup', true ) );
            break;
    }
}

add_filter( 'woocommerce_shop_order_search_fields', 'order_pickup_search_fields', 10, 1 );
function order_pickup_search_fields( $meta_keys ){
    $meta_keys[] = 'order_pickup';
    return $meta_keys;
}

How can I create custom dropdown filter where I will be able to filter orders based on mentioned ‘order_pickup’ so that I can have output like this:

‘order_pickup’ – number of ordered products based on category – total price of ordered products based on category

Example: Place: Shop – 40 ordered products (Food category) – 200 Euro total (Food category)

0
Marek Kozela 2 months 0 Answers 17 views 0

Leave an answer