Learn how to fix an issue with missing images for product variations inside the search results page.
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.
What we expect to see in this case - product variations must display parent product featured images.
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.