How to remove WooCommerce product featured image on the product image gallery

WooCommerce allows you to upload a featured image and multiple thumbnail images when you create a product.

The featured image represents the product in product archive pages like the Shop page, home page, category page, product search results page, etc. WooCommerce also uses the featured image on the single product page along with thumbnail images in the product image gallery.

But some shops may not want to include the featured image in the product image gallery. In this blog, we show you how to remove the WooCommerce product featured image from the product image gallery in single product single pages.

Add the code snippet to functions.php

/**
 * 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 remove_featured_image($html, $attachment_id ) {
    global $post;
    // 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', 'remove_featured_image', 10, 2);