Add WooCommerce Category Images to the Archive Page
By default WooCommerce doesn’t display category images on the products archive page. Here is a snippet that will allow you to automatically add category images without modifying your theme files. Simply copy and paste the following code in your functions.php file, within your theme folder.
<?php
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="" />';
}
}
}
Of course this snippet is the very basic, you can add custom CSS classes, IDs and more, but that’s a pretty good start. Simply keep in mind that WooCommerce doesn’t show category images by default and that’s intended, it’s not a bug. Feel free to r-use that snippet and make it your own, also post a link to your shop page when you customized it! ;-)