Skip to content

Instantly share code, notes, and snippets.

@justinstern
Last active December 13, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinstern/4971794 to your computer and use it in GitHub Desktop.
Save justinstern/4971794 to your computer and use it in GitHub Desktop.
Pluggable function to only display images for parent categories
<?php
function woocommerce_subcategory_thumbnail( $category ) {
global $woocommerce;
// Modification: don't show the image for subcategories
if ( $category->parent ) return;
$small_thumbnail_size = apply_filters( 'single_product_small_thumbnail_size', 'shop_catalog' );
$image_width = $woocommerce->get_image_size( 'shop_catalog_image_width' );
$image_height = $woocommerce->get_image_size( 'shop_catalog_image_height' );
$thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
if ( $thumbnail_id ) {
$image = wp_get_attachment_image_src( $thumbnail_id, $small_thumbnail_size );
$image = $image[0];
} else {
$image = woocommerce_placeholder_img_src();
}
if ( $image )
echo '<img src="' . $image . '" alt="' . $category->name . '" width="' . $image_width . '" height="' . $image_height . '" />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment