Skip to content

Instantly share code, notes, and snippets.

@kreamweb
Created July 29, 2015 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreamweb/8b1fd6b75f5f93d95488 to your computer and use it in GitHub Desktop.
Save kreamweb/8b1fd6b75f5f93d95488 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment