Filter by stock status
This commit is contained in:
parent
0390cf3e26
commit
0eba98a4e7
|
@ -301,8 +301,9 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
|
|||
* Render any custom filters and search inputs for the list table.
|
||||
*/
|
||||
protected function render_filters() {
|
||||
$current_category_slug = isset( $_REQUEST['product_cat'] ) ? wc_clean( wp_unslash( $_REQUEST['product_cat'] ) ) : false; // WPCS: input var ok, sanitization ok.
|
||||
$current_product_type = isset( $_REQUEST['product_type'] ) ? wc_clean( wp_unslash( $_REQUEST['product_type'] ) ) : false; // WPCS: input var ok, sanitization ok.
|
||||
$current_category_slug = isset( $_REQUEST['product_cat'] ) ? wc_clean( wp_unslash( $_REQUEST['product_cat'] ) ): false; // WPCS: input var ok, sanitization ok.
|
||||
$current_product_type = isset( $_REQUEST['product_type'] ) ? wc_clean( wp_unslash( $_REQUEST['product_type'] ) ): false; // WPCS: input var ok, sanitization ok.
|
||||
$current_stock_status = isset( $_REQUEST['stock_status'] ) ? wc_clean( wp_unslash( $_REQUEST['stock_status'] ) ): false; // WPCS: input var ok, sanitization ok.
|
||||
// @codingStandardsIgnoreStart
|
||||
$current_category = $current_category_slug ? get_term_by( 'slug', $current_category_slug, 'product_cat' ): false;
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
@ -364,6 +365,14 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
|
|||
|
||||
$output .= '</select>';
|
||||
|
||||
|
||||
$stock_statuses = wc_get_product_stock_status_options();
|
||||
$output .= '<select name="stock_status"><option value="">' . esc_html__( 'Filter by stock status', 'woocommerce' ) . '</option>';
|
||||
foreach ( $stock_statuses as $status => $label ) {
|
||||
$output .= '<option ' . selected( $status, $current_stock_status, false ) . ' value="' . esc_attr( $status ) . '">' . esc_html( $label ) . '</option>';
|
||||
}
|
||||
$output .= '</select>';
|
||||
|
||||
echo apply_filters( 'woocommerce_product_filters', $output ); // WPCS: XSS ok.
|
||||
}
|
||||
|
||||
|
@ -374,6 +383,7 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
|
|||
* @return array
|
||||
*/
|
||||
protected function query_filters( $query_vars ) {
|
||||
|
||||
if ( isset( $query_vars['orderby'] ) ) {
|
||||
if ( 'price' === $vars['orderby'] ) {
|
||||
// @codingStandardsIgnoreStart
|
||||
|
@ -416,6 +426,17 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
|
|||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $_GET['stock_status'] ) ) {
|
||||
if ( ! isset( $query_vars['meta_query'] ) ) {
|
||||
$query_vars['meta_query'] = array();
|
||||
}
|
||||
|
||||
$query_vars['meta_query'][] = array(
|
||||
'key' => '_stock_status',
|
||||
'value' => esc_attr( $_GET['stock_status'] ),
|
||||
);
|
||||
}
|
||||
|
||||
return $query_vars;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue