Last active
April 12, 2017 13:43
-
-
Save EricBusch/0c47b8fa97996205566dcd1f19d58184 to your computer and use it in GitHub Desktop.
Limit the total number of results a Comparison Set displays. [datafeedr][dfrcs]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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