'Display different images on shop/catalog page and single product page

I am using Woocommerce and I am trying to display different product images on the shop/catalog page from the single product page. By default, the shop shows the feature image on the shop page and single product page.

What I am trying to do is to not display the feature image on the single product page. That way, the feature image would only show on the shop/catalog page; and on the single product page, it would show the images from the gallery.

I have tried using this code and wan able to not show the feature image on the single product page, but the gallery gets messy. It leaves a blank space where the feature image should be.

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; }

Does someone knows how to take the feature image from the gallery of the single product page?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source