How can I hide the featured image of any product variety from the gallery? The products on my website are in "Variations" and the codes I saw are for "simple products". I use (alt = "MainImage") for featured images, but the following jQuery code did not work either.
$('[alt="MainImage"]').hide();
$('[alt="MainImage"]').parent().hide();
$('[alt="MainImage"]').css( "display", "none" );
$('div[data-thumb-alt="MainImage"]').hide();
$('img[alt="MainImage"]').css( "display", "none" );
$('img[data-thumb-alt="MainImage"]').hide();
$('div[title="Tajkan_0101"]').hide();
// :|
<img width="234" height="400" src="https://.../wp-content/uploads/2021/09/Tajkan_0101.jpg" class="" alt="MainImage" loading="lazy" title="Tajkan_0101" data-caption="" data-src="https://.../wp-content/uploads/2021/09/Tajkan_0101.jpg" data-large_image="https://.../wp-content/uploads/2021/09/Tajkan_0101.jpg" data-large_image_width="234" data-large_image_height="400" srcset="https://.../wp-content/uploads/2021/09/Tajkan_0101.jpg 234w, https://.../wp-content/uploads/2021/09/Tajkan_0101-176x300.jpg 176w" sizes="(max-width: 234px) 100vw, 234px" draggable="false">
Unfortunately, this code is only for simple products:
add_filter('woocommerce_single_product_image_thumbnail_html', 'remove_featured_image', 10, 2);
function remove_featured_image($html, $attachment_id ) {
global $post, $product;
$featured_image = get_post_thumbnail_id( $post->ID );
if ( $attachment_id == $featured_image )
$html = '';
return $html;
}