Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Last active April 12, 2017 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricBusch/0c47b8fa97996205566dcd1f19d58184 to your computer and use it in GitHub Desktop.
Save EricBusch/0c47b8fa97996205566dcd1f19d58184 to your computer and use it in GitHub Desktop.
Limit the total number of results a Comparison Set displays. [datafeedr][dfrcs]
<?php
/**
* Limit the total number of results in a Comparison Set to 5.
*
* Change the value of $max_results to modify the number of results returned.
*
* @param array $filtered_products Array of products after pre-filters have been run.
* @param array $all_products Array of products before any pre-filters have been run.
*
* @return array Updated $filtered_products array.
*/
add_filter( 'dfrcs_filter_products', 'mycode_limit_results', 20, 2 );
function mycode_limit_results( $filtered_products, $all_products ) {
$max_results = 5;
if ( ! empty( $filtered_products ) ) {
$filtered_products = array_slice( $filtered_products, 0, $max_results );
}
return $filtered_products;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment