Help Docs Software Kadence Kadence Iconic Kadence Iconic Show Single Variations Fix: Product Variations Not Using the Parent Product Image

Fix: Product Variations Not Using the Parent Product Image

Depending on how your theme is retrieving product images, it can show the placeholder image instead of falling back to the parent product image.

For example, the variation shown below has no image set up but the main parent product has:

product variation fix

In this scenario, by default, the product variation will use the parent product image. But if you access the shop page and it’s showing a placeholder instead, it’ll be necessary to add a custom code to your theme so it can use the parent product image.

variation placeholder image

To do this, add the code below to your functions.php file:

add_filter(
	'post_thumbnail_id',
	function( $thumbnail_id, $post ) {

		if ( is_admin() ) {
			return $thumbnail_id;
		}

		if ( ! empty( $thumbnail_id ) ) {
			return $thumbnail_id;
		}

		if ( 'product_variation' !== $post->post_type ) {
			return $thumbnail_id;
		}

		$parent_post_thubmnail_id = get_post_thumbnail_id( $post->post_parent );

		if ( empty( $parent_post_thubmnail_id ) ) {
			return $thumbnail_id;
		}

		return $parent_post_thubmnail_id;
	},
	20,
	2
);

This code adds a filter to WordPress to fall back to the parent product image if the variation has no image.

variation fallback image fix
Was this article helpful?