Last active
December 13, 2015 20:39
-
-
Save justinstern/4971794 to your computer and use it in GitHub Desktop.
Pluggable function to only display images for parent categories
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
<?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