• Resolved burgerino

    (@burgerino)


    Hi, thanks for this wonderful plugin. I wanted to ask if it is possible to show product categories in the search?

    For example if i am typing in “chair”, it would show
    “chair > kitchen”
    “chair > living room”

    Thanks
    Z

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    So you want to display these categories inside the plugin live search results box or and inside the search results page too?

    Anyway – please go to the plugin settings page, find the ‘Archive pages’ option and enable the ‘Category’ option for you.?

    Regards

    Thread Starter burgerino

    (@burgerino)

    Thanks

    I would like to have categories shown inside the plugin live search results box. So that the user would be able to narrow down the search by selecting chairs from the specific category.

    Regards

    Plugin Author ILLID

    (@mihail-barinov)

    In this case just go to the plugin settings page, find the ‘Archive pages’ option and enable the ‘Category’ option for you.

    Thread Starter burgerino

    (@burgerino)

    Sorry I was not clear. I would like to have the category typed in the result box, for subcategories or products, just like the price, SKU or descriptions is shown.

    What you are suggesting is that I would be able to search for subcategories or categories using the search box. Even though I am searching for the subcategory, the suggested results for subcategories are not showing the category it belongs to.

    • This reply was modified 3 years, 10 months ago by burgerino.
    Plugin Author ILLID

    (@mihail-barinov)

    Looks like I found the solution for you. Please use following code snippet

    add_filter( 'aws_excerpt_search_result', 'aws_excerpt_search_result', 10, 3 );
    function aws_excerpt_search_result( $excerpt, $post_id, $product ) {
        $terms = get_the_terms( $post_id, 'product_cat' );
        $terms_arr = array();
        if ( ! is_wp_error( $terms ) && !empty( $terms ) ) {
            foreach ( $terms as $term ) {
                $terms_arr[] = $term->name;
            }
            $term_string = implode(',', $terms_arr);
            if ( $term_string ) {
                $excerpt .= '<br>' . '<span style="padding: 6px 0 6px;display: block;">' . $term_string . '</span>';
            }
        }
        return $excerpt;
    }
    
    add_filter( 'aws_search_tax_results', 'my_aws_search_tax_results', 10, 2 );
    function my_aws_search_tax_results( $results, $taxonomy ) {
        if ( isset( $results['product_cat'] ) ) {
            foreach( $results['product_cat'] as $key => $cat_item ) {
                $term = get_term( $cat_item['id'], 'product_cat' );
                if ( $term && $term->parent ) {
                    $termParent = get_term($term->parent, 'product_cat');
                    if ( $termParent ) {
                        $results['product_cat'][$key]['excerpt'] .= $termParent->name;
                    }
                }
    
            }
        }
        return $results;
    }

    You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.

    Also after adding this code you will need to go to the plugin settings page and click the ‘Clear cache’ button.

    Thread Starter burgerino

    (@burgerino)

    Thanks! this is exactly what I’ve needed! Wonderful

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘showing categories in the search’ is closed to new replies.