Introduced product category filter threshold and load categories dropdown
Only use WooSelect when have more than 100 terms
This commit is contained in:
parent
487c039b1c
commit
f27120f649
|
@ -1457,15 +1457,23 @@ class WC_Admin_Post_Types {
|
||||||
global $wp_query;
|
global $wp_query;
|
||||||
|
|
||||||
// Category Filtering.
|
// Category Filtering.
|
||||||
$current_category_slug = isset( $_GET['product_cat'] ) ? wc_clean( wp_unslash( $_GET['product_cat'] ) ) : false; // WPCS: input var ok, CSRF ok.
|
$categories_count = (int) wp_count_terms( 'product_cat' );
|
||||||
$current_category = $current_category_slug ? get_term_by( 'slug', $current_category_slug, 'product_cat' ) : false;
|
if ( $categories_count <= apply_filters( 'woocommerce_product_category_filter_threshold', 100 ) ) {
|
||||||
?>
|
wc_product_dropdown_categories( array(
|
||||||
<select class="wc-category-search" name="product_cat" data-placeholder="<?php esc_attr_e( 'Filter by category', 'woocommerce' ); ?>" data-allow_clear="true">
|
'option_select_text' => __( 'Filter by category', 'woocommerce' ),
|
||||||
<?php if ( $current_category_slug && $current_category ) : ?>
|
) );
|
||||||
<option value="<?php echo esc_attr( $current_category_slug ); ?>" selected="selected"><?php echo esc_html( $current_category->name ); ?><option>
|
} else {
|
||||||
<?php endif; ?>
|
|
||||||
</select>
|
$current_category_slug = isset( $_GET['product_cat'] ) ? wc_clean( wp_unslash( $_GET['product_cat'] ) ) : false; // WPCS: input var ok, CSRF ok.
|
||||||
<?php
|
$current_category = $current_category_slug ? get_term_by( 'slug', $current_category_slug, 'product_cat' ) : false;
|
||||||
|
?>
|
||||||
|
<select class="wc-category-search" name="product_cat" data-placeholder="<?php esc_attr_e( 'Filter by category', 'woocommerce' ); ?>" data-allow_clear="true">
|
||||||
|
<?php if ( $current_category_slug && $current_category ) : ?>
|
||||||
|
<option value="<?php echo esc_attr( $current_category_slug ); ?>" selected="selected"><?php echo esc_html( $current_category->name ); ?><option>
|
||||||
|
<?php endif; ?>
|
||||||
|
</select>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
// Type filtering.
|
// Type filtering.
|
||||||
$terms = get_terms( 'product_type' );
|
$terms = get_terms( 'product_type' );
|
||||||
|
|
Loading…
Reference in New Issue