Step 1: Open functions.php file

Open the WordPress admin dashboard of your WooCommerce store and head on to Appearance > Theme editor from the left sidebar.

Once you are in the Theme Editor page, you can see a text editor in the middle and list of files in your theme on the left side.

From the theme files, click on functions.php file.

Now you can see your theme’s functions.php file opened on the text editor screen in the middle of the page.

Step 2: Copy the following code snippet


/**
 * Exclude the featured image from appearing in the product gallery, if there's a product gallery.
 *
 * @param array $html Array of html to output for the product gallery.
 * @param array $attachment_id ID of each image variables.
 */
function rm_woocommerce_remove_featured_image( $html, $attachment_id ) {
	global $post, $product;
	// Get the IDs.
	$attachment_ids = $product->get_gallery_image_ids();
	// If there are none, go ahead and return early - with the featured image included in the gallery.
	if ( ! $attachment_ids ) {
		return $html;
	}
	// Look for the featured image.
	$featured_image = get_post_thumbnail_id( $post->ID );
	// If there is one, exclude it from the gallery.
	if ( is_product() && $attachment_id === $featured_image ) {
		$html = '';
	}
	return $html;
}
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'rm_woocommerce_remove_featured_image', 10, 2 );

Step 3: Add the code snippet to functions.php

Now go back to the Theme Editor screen in the WordPress admin area. In the first step, you have opened the functions.php file on the text editor.

Click anywhere on the text editor and scroll to the bottom of the funcitons.php file and paste the above code at the end.

Step 4: Save changes

Click on the Save changes button at the bottom of the text editor screen. Now you have successfully added the code snippet required to hide product featured image from the product image gallery on single product pages.

Summary

Sometimes you may don’t want to show the product featured image in the product image gallery in the single product page but there WooCommerce doesn’t provide you the option do configure your store that way. However, it is not difficult to achieve what you want. All you need to add a small snippet to of PHP code to the functions.php file on your theme.