kreamweb
7/29/2015 - 7:41 AM

Ajax Search from Premium to Free

Ajax Search from Premium to Free

<?php
if( defined('YITH_WCAS_PREMIUM') ){
	global $yith_wcas;
	add_filter( 'ywrac_results', 'ywrac_custom_result', 10, 2 );
	remove_action( 'pre_get_posts', array( $yith_wcas, 'pre_get_posts' ) );
}
function ywrac_custom_result( $posts, $search_keyword ){
	global $woocommerce;
	$ordering_args = $woocommerce->query->get_catalog_ordering_args( 'title', 'asc' );

	$args = array(
		's'                   => apply_filters( 'yith_wcas_ajax_search_products_search_query', $search_keyword ),
		'post_type'           => 'product',
		'post_status'         => 'publish',
		'ignore_sticky_posts' => 1,
		'orderby'             => $ordering_args['orderby'],
		'order'               => $ordering_args['order'],
		'posts_per_page'      => apply_filters( 'yith_wcas_ajax_search_products_posts_per_page', get_option( 'yith_wcas_posts_per_page' ) ),
		'suppress_filters'    => false,
		'meta_query'          => array(
			array(
				'key'     => '_visibility',
				'value'   => array( 'search', 'visible' ),
				'compare' => 'IN'
			)
		)
	);

	if ( isset( $_REQUEST['product_cat'] ) ) {
		$args['tax_query'] = array(
			'relation' => 'AND',
			array(
				'taxonomy' => 'product_cat',
				'field'    => 'slug',
				'terms'    => $_REQUEST['product_cat']
			) );
	}

	$products = get_posts( $args );

	return $products;
}