Support » Plugin: Ajax Search for WooCommerce » Include Product Category in Results List

  • Resolved jbenes

    (@jbenes)


    Hi,
    Is there any way the product category can be included in the results list? I would like to have some like:

    Category Name – Product 1
    Category Name – Product 2
    etc.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,
    Just wanted to follow up and see if this is possible. We’d be happy to purchase a Pro license if this is an included capability.

    Thank you.

    Plugin Author Damian Gora

    (@damian-gora)

    It’s possibile. Here is solutions for Free version:

    
    add_filter( 'dgwt/wcas/search_results/products', function ( $suggestion, $product ) {
    
    	if ( ! empty( $suggestion['value'] ) ) {
    
    		$categories = $product->getTerms( 'product_cat', 'string' );
    		if ( ! empty( $categories ) ) {
    			$suggestion['value'] = $categories . ' - ' . $suggestion['value'];
    		}
    		
    	}
    
    	return $suggestion;
    }, 10, 2 );
    

    You have two ways to add this code to your theme:

    1. Open the functions.php in your Child Theme and add the code at the end
    2. or install the Code Snippets plugin and apply this code as a snippet

    The solution for the Pro version will be different. If you are interested in the pro version, contact me via https://ajaxsearch.pro/contact/ after purchase. Then I send you solutions that work with the Pro version.

    Best
    Damian

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.