This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: For Variable Products display parent image if there is no specific image

Home Forums Product Support Forums Ajax Search Pro for WordPress Support For Variable Products display parent image if there is no specific image Reply To: For Variable Products display parent image if there is no specific image

#22662
Ernest MarcinkoErnest Marcinko
Keymaster

Hi!

It might be possible via using a small custom code snippet. Try add this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

add_filter( 'asp_results', 'asp_get_main_prod_img', 10, 1 );
function asp_get_main_prod_img($results) {
	foreach ( $results as $k => &$r ) {
		if ( isset($r->post_type) && $r->post_type == 'product_variation' ) {
			$wc_prod_var_o = wc_get_product( $r->id );
			$img = wp_get_attachment_image_src(
				get_post_thumbnail_id($wc_prod_var_o->get_parent_id()),
				'single-post-thumbnail'
			);
			if (isset($img, $img[0]) && !is_wp_error($img))
				$r->image = $img[0];
		}
	}
	return $results;
}

This should hopefully resolve the issue.