'product', 'posts_per_page' => $posts_per_page, 's' => $search_term, 'order' => $order, 'orderby' => $orderby, 'post_status' => array( 'publish' ) ); if( $orderby === 'price' ) { $args[ 'meta_key' ] = '_price'; $args[ 'orderby' ] = 'meta_value_num'; } $output = ''; $qry = new WP_Query( $args ); // Enable search by SKU if( $enable_search_by_sku ) { $args = array( 'post_type' => array( 'product', 'product_variation' ), 'posts_per_page' => $posts_per_page, 'order' => $order, 'orderby' => $orderby, 'post_status' => array( 'publish' ), 'meta_query' => array( 'relation' => 'OR', array( 'key' => '_sku', 'value' => $search_term, 'compare' => 'LIKE' ) ) ); if( $orderby === 'price' ) { $args[ 'meta_key' ] = '_price'; $args[ 'orderby' ] = 'meta_value_num'; } $qry_sku = new WP_Query( $args ); $qry->posts = array_merge( $qry->posts, $qry_sku->posts ); $qry->post_count = count( $qry->posts ); } if( $qry->have_posts() ) : $output .= '
'. esc_html__( 'No products found.', 'botiga' ) .'
'; wp_send_json( array( 'status' => 'success', 'type' => 'no-results', 'output' => wp_kses_post( $output ) ) ); } } add_action('wp_ajax_botiga_ajax_search_callback', 'botiga_ajax_search_callback'); add_action('wp_ajax_nopriv_botiga_ajax_search_callback', 'botiga_ajax_search_callback');