'; } public function get_search_results_list_item( $product_id ) { $product = wc_get_product( $product_id ); if ( ! $product ) { return ''; } ob_start(); ?>
  • get_image(); ?>

    get_name() ); ?>

    get_short_description() ); ?>

    get_price_html(); ?>

  • ' . esc_html( 'View all results', 'aihub-core' ) . ''; } public function get_products_by_input_text() { $search_text = strval( $_POST[ 'searchText' ] ); $category_id = intval( $_POST[ 'termId' ] ); $args = [ 'post_type' => 'product', 's' => $search_text, 'posts_per_page' => 5, ]; if ( $category_id ) { $parent_category = get_term( $category_id, 'product_cat' ); $categories = get_term_children( $parent_category->term_id, 'product_cat' ); $categories = array_merge( $categories, [ $parent_category->term_id ] ); $args[ 'tax_query' ] = [ [ 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $categories, 'operator' => 'IN' ] ]; } $query = new \WP_Query( $args ); if ( $query->have_posts() ) { $products = []; $found_products = $query->get_posts(); foreach ( $found_products as $product ) { $products[] = $this->get_search_results_list_item( $product->ID ); } if ( $query->found_posts > $query->post_count ) { $output = $this->get_search_results_wrap_start() . implode( '', $products ) . $this->get_search_results_view_all() . $this->get_search_results_wrap_end(); } else { $output = $this->get_search_results_wrap_start() . implode( '', $products ) . $this->get_search_results_wrap_end(); } } else { ob_start(); wc_no_products_found(); $output = $this->get_search_results_wrap_start() . ob_get_clean() . $this->get_search_results_wrap_end(); } wp_send_json_success( [ 'html' => $output ] ); } } new LQD_Woo_AjaxSearch_Handler();