get_product_details( $product_id ); } } // Get taxonomy details if ( isset( $_REQUEST[ 'term_id' ] ) && isset( $_REQUEST[ 'taxonomy' ] ) ) { $term_id = is_numeric( $_REQUEST[ 'term_id' ] ) && $_REQUEST[ 'term_id' ] > 0 ? absint( $_REQUEST[ 'term_id' ] ) : false; if ( $term_id !== false ) { $html = ''; switch ( $_REQUEST[ 'taxonomy' ] ) { case 'product_cat': $html = $this->get_taxonomy_details( $term_id, 'product_cat', $suggestion ); break; case 'product_tag': $html = $this->get_taxonomy_details( $term_id, 'product_tag', $suggestion ); break; } } } $output[ 'details' ] = $html; $object_id = 0; $type = ''; if(!empty($product_id)){ $type = 'product'; $object_id = $product_id; } if(!empty($term_id)){ $type = 'term'; $object_id = $term_id; } echo json_encode( apply_filters( 'dgwt/wcas/suggestion_details/output', $output, $type, $object_id )); die(); } /** * Prepare products details to the ajax output * * @param int $product_id * @param string $value Suggestion value * * @return string HTML */ private function get_product_details( $product_id ) { $html = ''; $product = new Product( $product_id ); if ( empty( $product) ) { return; } $details = array( 'id' => $product->getID(), 'desc' => '', ); // Get product desc $details[ 'desc' ] = Helpers::get_product_desc( $product->getWooObject(), 500 ); ob_start(); include_once DGWT_WCAS_DIR . 'partials/single-product.php'; $html = ob_get_clean(); return $html; } /** * Prepare category details to the ajax output * * @param int $term_id * @param string taxonomy * @param string $suggestion Suggestion value * * @return string HTML */ private function get_taxonomy_details( $term_id, $taxonomy, $suggestion ) { $html = ''; $title = ''; ob_start(); $query_args = $this->get_taxonomy_query_args(); // Serach with specific category $query_args[ 'tax_query' ][] = array( 'taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_id, 'include_children' => true, ); $products = new \WP_Query( $query_args ); if ( $products->have_posts() ) { // Details box title $title .= ''; $title .= ''; if ( 'product_cat' === $taxonomy ) { $title .= __( 'Category', 'ajax-search-for-woocommerce' ) . ': '; } else { $title .= __( 'Tag', 'ajax-search-for-woocommerce' ) . ': '; } $title .= ''; $title .= $suggestion; $title .= ''; echo '