Skip to content

Instantly share code, notes, and snippets.

@clawfire
Created August 7, 2012 13:18
Show Gist options
  • Save clawfire/3285271 to your computer and use it in GitHub Desktop.
Save clawfire/3285271 to your computer and use it in GitHub Desktop.
Don't display placeholder and image if there's no picture defined for a category
<?php
// unload the original one
remove_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail');
// load mine
add_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail_custom', 10);
if ( ! function_exists( 'woocommerce_subcategory_thumbnail_custom' ) ) {
function woocommerce_subcategory_thumbnail_custom( $category ) {
global $woocommerce;
$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];
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