Refinery Product Recommendations provides filters that allow developers to customize recommendation behavior, caching, and data storage limits. Use these hooks in a custom plugin or in your theme’s functions.php.
Filters
refinery_product_recommendations_recommendations_enabled
Control whether product recommendations are displayed on the frontend. Return false to disable recommendations globally, or apply conditional logic to disable them for specific pages or user roles.
apply_filters( 'refinery_product_recommendations_recommendations_enabled', mixed $enabled )
Parameters:
$enabled(mixed) — The current enabled state. Defaults to the value of therefinery_product_recommendations_enable_recommendationsoption.
Example:
// Disable recommendations for logged-out users.
add_filter( 'refinery_product_recommendations_recommendations_enabled', function( $enabled ) {
if ( ! is_user_logged_in() ) {
return false;
}
return $enabled;
} );
refinery_product_recommendations_recommendations_cache_duration
Filter the cache duration for recommendation results. Recommendations are stored in transients to avoid recalculating on every page load.
apply_filters( 'refinery_product_recommendations_recommendations_cache_duration', int $duration )
Parameters:
$duration(int) — Cache duration in seconds. Default is3600(1 hour).
Example:
// Cache recommendations for 24 hours.
add_filter( 'refinery_product_recommendations_recommendations_cache_duration', function( $duration ) {
return DAY_IN_SECONDS;
} );
Set to 0 to disable caching entirely. This is not recommended in production as it increases database load on every product page view.
refinery_product_recommendations_max_stored_refs_per_product
Filter the maximum number of reference products stored per product during relevancy generation. A higher value provides more recommendation candidates but increases database size.
apply_filters( 'refinery_product_recommendations_max_stored_refs_per_product', int $max, int $display_count, string $strategy_key )
Parameters:
$max(int) — The calculated maximum, based on display count multiplied by 3, clamped between 12 and 60.$display_count(int) — The highest recommendation count configured across all placements.$strategy_key(string) — The strategy key being generated (e.g.,'default').
Example:
// Store more candidates for larger catalogs.
add_filter( 'refinery_product_recommendations_max_stored_refs_per_product', function( $max, $display_count, $strategy_key ) {
return 100;
}, 10, 3 );