WC_Admin_List_Table_Products::query_filters()
Handle any custom filters.
Method of the class: WC_Admin_List_Table_Products{}
No Hooks.
Return
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_Products::query_filters() WC Admin List Table Products::query filters code WC 9.4.2
protected function query_filters( $query_vars ) { $this->remove_ordering_args(); // Custom order by arguments. if ( isset( $query_vars['orderby'] ) ) { $orderby = strtolower( $query_vars['orderby'] ); $order = isset( $query_vars['order'] ) ? strtoupper( $query_vars['order'] ) : 'DESC'; if ( 'price' === $orderby ) { $callback = 'DESC' === $order ? 'order_by_price_desc_post_clauses' : 'order_by_price_asc_post_clauses'; add_filter( 'posts_clauses', array( $this, $callback ) ); } if ( 'sku' === $orderby ) { $callback = 'DESC' === $order ? 'order_by_sku_desc_post_clauses' : 'order_by_sku_asc_post_clauses'; add_filter( 'posts_clauses', array( $this, $callback ) ); } } // Type filtering. if ( isset( $query_vars['product_type'] ) ) { if ( 'downloadable' === $query_vars['product_type'] ) { $query_vars['product_type'] = ''; add_filter( 'posts_clauses', array( $this, 'filter_downloadable_post_clauses' ) ); } elseif ( 'virtual' === $query_vars['product_type'] ) { $query_vars['product_type'] = ''; add_filter( 'posts_clauses', array( $this, 'filter_virtual_post_clauses' ) ); } } // Stock status filter. if ( ! empty( $_GET['stock_status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended add_filter( 'posts_clauses', array( $this, 'filter_stock_status_post_clauses' ) ); } // Shipping class taxonomy. if ( ! empty( $_GET['product_shipping_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $query_vars['tax_query'][] = array( 'taxonomy' => 'product_shipping_class', 'field' => 'slug', 'terms' => sanitize_title( wp_unslash( $_GET['product_shipping_class'] ) ), 'operator' => 'IN', ); } // Search using CRUD. if ( ! empty( $query_vars['s'] ) ) { $data_store = WC_Data_Store::load( 'product' ); $ids = $data_store->search_products( wc_clean( wp_unslash( $query_vars['s'] ) ), '', true, true ); $query_vars['post__in'] = array_merge( $ids, array( 0 ) ); $query_vars['product_search'] = true; unset( $query_vars['s'] ); } return $query_vars; }