WC_Admin_List_Table_Products::query_filters( array $query_vars )
Handle any custom filters.
Description Description
Parameters Parameters
- $query_vars
-
(Required) Query vars.
Return Return
(array)
Source Source
File: includes/admin/list-tables/class-wc-admin-list-table-products.php
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; }