GET FREE VERSION GET THE PRO VERSION

No product variation images on search page

Learn how to fix an issue with missing images for product variations inside the search results page.

In this article

Overview

With the Advanced Woo Search PRO you have a special feature to search and display product variations.

You can show them on both - ajax results block and inside search results page.

Some WordPress themes may have problems in displaying images for the product variations inside that search results pages. This problem is not related to Advanced Woo Search plugins itself as it is not having its own template for search results page and just inherits its results to the current existing one.

Product variations images are not displayed for the search results page

Product variations images are not displayed for the search results page

What we expect to see in this case - product variations must display parent product featured images.

Product variations with parent product images

Product variations with parent product images

Solution

So we want to fix missing images for product variations inside the search results page and display parent product images in this case.

To do this just use the following code snippet:

add_filter( 'post_thumbnail_id', 'my_post_thumbnail_id', 10, 2 );
function my_post_thumbnail_id( $thumbnail_id, $post ) {
    if ( isset( $_GET['type_aws'] ) && ! $thumbnail_id && $post->post_type === 'product_variation' && $post->post_parent ) {
        $thumbnail_id = (int) get_post_meta( $post->post_parent, '_thumbnail_id', true );
    }
    return $thumbnail_id;
}

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.