Skip to content

Instantly share code, notes, and snippets.

@jameskoster
Last active July 29, 2022 10:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jameskoster/5042430 to your computer and use it in GitHub Desktop.
Save jameskoster/5042430 to your computer and use it in GitHub Desktop.
WooCommerce - display category image on category archive
add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="' . $cat->name . '" />';
}
}
}
@tiknius
Copy link

tiknius commented Sep 21, 2015

Hi, how this code can be edited so parent category image is also displayed when viewing child categories? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment