WC_Admin_List_Table_Orders::query_filters
Handle any custom filters.
Method of the class: WC_Admin_List_Table_Orders{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->query_filters( $query_vars );
- $query_vars(array) (required)
- Query vars.
WC_Admin_List_Table_Orders::query_filters() WC Admin List Table Orders::query filters code WC 10.3.6
protected function query_filters( $query_vars ) {
global $wp_post_statuses;
// Filter the orders by the posted customer.
if ( ! empty( $_GET['_customer_user'] ) ) { // WPCS: input var ok.
// @codingStandardsIgnoreStart.
$query_vars['meta_query'] = array(
array(
'key' => '_customer_user',
'value' => (int) $_GET['_customer_user'], // WPCS: input var ok, sanitization ok.
'compare' => '=',
),
);
// @codingStandardsIgnoreEnd
}
// Filter the orders by created via.
if ( ! empty( $_GET['_created_via'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
// @codingStandardsIgnoreStart
$created_via = explode(',', sanitize_text_field( wp_unslash( $_GET['_created_via'] ) ) );
$query_vars['meta_query'] = array(
array(
'key' => '_created_via',
'value' => $created_via,
'compare' => 'IN',
),
);
// @codingStandardsIgnoreEnd
}
// Sorting.
if ( isset( $query_vars['orderby'] ) ) {
if ( 'order_total' === $query_vars['orderby'] ) {
// @codingStandardsIgnoreStart
$query_vars = array_merge( $query_vars, array(
'meta_key' => '_order_total',
'orderby' => 'meta_value_num',
) );
// @codingStandardsIgnoreEnd
}
}
// Status.
if ( empty( $query_vars['post_status'] ) ) {
$post_statuses = wc_get_order_statuses();
foreach ( $post_statuses as $status => $value ) {
if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
unset( $post_statuses[ $status ] );
}
}
$query_vars['post_status'] = array_keys( $post_statuses );
}
return $query_vars;
}