YITH WooCommerce Ajax Product Filter Compatibility
The YITH Woocommerce Ajax Product Filter is a popular plugin that allows you to filter your WooCommerce products using a widget powered by Ajax. While it is a useful plugin, it makes many WP_Query calls to build its widget. This causes multiple requests to go through ElasticPress which in turn can cause performance problems on your site.
To alleviate this issue we have provided this snippet below. This will cut down the amount of queries sent to the ElasticPress.io service. Check out our Enhancing ElasticPress with Custom Functions article about adding code to your website.
/**
* Preventing ElasticPress to be used
*
* @param array $unfiltered_args filters used by YITH WooCommerce Ajax Product Filter plugin
* @return array
*/
function ep_prevent_using_ep_on_yith_wcan_unfiltered_args( $unfiltered_args ) {
$unfiltered_args['ep_integrate'] = false;
return $unfiltered_args;
}
add_filter( 'yith_wcan_unfiltered_args', 'ep_prevent_using_ep_on_yith_wcan_unfiltered_args' );
If the above code doesn’t work, you can try disabling it via the ElasticPress ep_skip_query_integration
filter by checking if the Yith filter is selected using the below code:
function ep_prevent_using_ep_on_yith_wcan( $ep_skip_query_integration, $query ) {
if ( ! empty( $query->get( 'yith_wcan_query' ) ) ) {
return true;
}
return $ep_skip_query_integration;
}
add_filter( 'ep_skip_query_integration', 'ep_prevent_using_ep_on_yith_wcan', 10, 2 );
If you run into any other issues concerning this plugin please reach out to support and we will be happy to help!