Category Images in Search Results Not Showing?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Category Images in Search Results Not Showing?

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 8 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4286
    James Scaggs
    James Scaggs
    Participant

    Hello,

    Is it possible to show image of “product category” in search results? I have images on my product categories in Woocommerce but they don’t show up next to categories in the search results.

    You should already have credentails for my site from yesterday.

    you can see search bar at http://harvill-ind.com/home-3

    #4290
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Yes it is actually. The search can’t show the term images, as there is no such thing by default in wordpress.
    However it is possible to add a few lines of code to your themes functions.php file, which will try to parse images for woocommerce terms:

    add_filter('asp_results', 'asp_get_woo_term_image'); 
    function asp_get_woo_term_image($results) {
      foreach($results as $k => $result) { 
        if ($result->content_type != 'term') continue;
        if (function_exists('get_woocommerce_term_meta') && empty($result->image)) {
          $thumbnail_id = get_woocommerce_term_meta( $result->id, 'thumbnail_id', true );
        	$image = wp_get_attachment_url( $thumbnail_id );
          if (!empty($image))
            $results[$k]->image = $image;
        }
      }
      return $results;
    } 

    This filtering function will parse through the results, and if it finds a woocommerce term image, it will attach it to the actual result. This solution is update ready, since you do not need to modify the search code.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #4310
    James Scaggs
    James Scaggs
    Participant

    Well I gave that a try cleared the all of my caches and minified js.

    I still can’t see the changes here: harvill-ind.com/home-3

    I want to make sure we are both talking about the same thing here. I have images set for my product category that I want to display in the search results when user hits enter before they choose a result.

    See attachment of where I have the image set on the product category and where I am wanting the image to display.

    Do you have any other ideas

    Attachments:
    You must be logged in to view attached files.
    #4318
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Yes, we are talking about the same thing.

    I think I know why it isn’t working. Version 4.0 just rolled out a few days ago, you might not get a notification from codecanyon.
    If you update, this solution should work.

    If you don’t want to update (if you have custom code or something applied), then try this code instead, it will probably work with version 3.5:

    
    add_filter('asp_results', 'asp_get_woo_term_image'); 
    function asp_get_woo_term_image($results) {
      foreach($results as $k => $result) { 
        if (function_exists('get_woocommerce_term_meta') && empty($result->image)) {
          $thumbnail_id = get_woocommerce_term_meta( $result->id, 'thumbnail_id', true );
            $image = wp_get_attachment_url( $thumbnail_id );
          if (!empty($image))
            $results[$k]->image = $image;
        }
      }
      return $results;
    }
    
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Category Images in Search Results Not Showing?’ is closed to new replies.