woocommerce_json_search_limit filter

This commit is contained in:
Mike Jolley 2018-06-09 17:22:26 +01:00
parent c2616b74f2
commit 81149157a3
1 changed files with 7 additions and 5 deletions

View File

@ -1392,8 +1392,14 @@ class WC_AJAX {
wp_die(); wp_die();
} }
if ( ! empty( $_GET['limit'] ) ) {
$limit = absint( $_GET['limit'] );
} else {
$limit = absint( apply_filters( 'woocommerce_json_search_limit', 30 ) );
}
$data_store = WC_Data_Store::load( 'product' ); $data_store = WC_Data_Store::load( 'product' );
$ids = $data_store->search_products( $term, '', (bool) $include_variations ); $ids = $data_store->search_products( $term, '', (bool) $include_variations, false, $limit );
if ( ! empty( $_GET['exclude'] ) ) { if ( ! empty( $_GET['exclude'] ) ) {
$ids = array_diff( $ids, (array) $_GET['exclude'] ); $ids = array_diff( $ids, (array) $_GET['exclude'] );
@ -1403,10 +1409,6 @@ class WC_AJAX {
$ids = array_intersect( $ids, (array) $_GET['include'] ); $ids = array_intersect( $ids, (array) $_GET['include'] );
} }
if ( ! empty( $_GET['limit'] ) ) {
$ids = array_slice( $ids, 0, absint( $_GET['limit'] ) );
}
$product_objects = array_filter( array_map( 'wc_get_product', $ids ), 'wc_products_array_filter_readable' ); $product_objects = array_filter( array_map( 'wc_get_product', $ids ), 'wc_products_array_filter_readable' );
$products = array(); $products = array();