Hi. How can we help?

Ajax Search 2.x and Barn2 WooCommerce Product table

With the new version of Ajax search, the product table added by barn2 product table is not filtered by the search query.
By adding this code to your theme's functions.php, the table is filtered correctly.

add_filter( 'wc_product_table_args', 'ywcas_barn2_product_table_compatibility', 100, 1 );

if ( ! function_exists( 'ywcas_barn2_product_table_compatibility' ) && function_exists('ywcas_get_current_language') ) {
function ywcas_barn2_product_table_compatibility( $query_args ) {
if( isset( $_GET['ywcas'] ) ){
$lang = isset( $_GET['lang'] ) ? sanitize_text_field( wp_unslash( $_GET['lang'] ) ) : ywcas_get_current_language();
$search_on = ywcas_get_default_product_post_type();
$post_in = array();
if ( isset( $_GET['ywcas_filter'] ) ) {
global $wp_query;
$search = sanitize_text_field( wp_unslash( $_GET['ywcas_filter'] ) );
$taxonomy = $wp_query ? get_queried_object() : false;
$search_on = ywcas_get_default_product_post_type();
if ( $taxonomy ) {
$results = YITH_WCAS_Data_Search_Engine::get_instance()->search( $search, $search_on, 0, $lang, false, 0, 0, true );
$post_in = array_map( 'intval', wp_list_pluck( $results['results'], 'post_id' ) );

}
}else{
$search = sanitize_text_field( wp_unslash( $_GET['s'] ) );
$results = YITH_WCAS_Data_Search_Engine::get_instance()->search( $search, $search_on, 0, $lang, false, 0, 0, true );

$post_in = array_map( 'intval', wp_list_pluck( $results['results'], 'post_id' ) );
}

$query_args['include'] = $post_in;
$query_args['search_term'] = $search;
}


return $query_args;
}
}
Was this article helpful?
0 out of 0 found this helpful

Back to Help Center >