Last active
September 2, 2021 09:43
-
-
Save mitchellkrogza/4d8803c905670dc4e6adf95551eb2e88 to your computer and use it in GitHub Desktop.
Woocommerce Hide Featured Image from Specific Category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Useful function to hide the product featured image for all products in specific categories | |
// The main image displayed when visiting products in these categories becomes the first gallery image | |
// Written by Mitchell Krog - mitchellkrog@gmail.com | |
// Replace categoryslug2 / categoryslug1 with your category slug (add to array as needed) | |
add_filter('woocommerce_single_product_image_thumbnail_html', 'remove_featured_image', 10, 2); | |
function remove_featured_image($html, $attachment_id ) { | |
global $product; | |
if( ! has_term( array( 'categoryslug1', 'categoryslug2' ) , 'product_cat', $product->get_id() ) ){ | |
return $html; | |
} | |
else | |
{ | |
$featured_image = get_post_thumbnail_id( $post->ID ); | |
if ( $attachment_id == $featured_image ) | |
$html = ''; | |
return $html; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment