jeudi 30 juin 2016

How can I add the thumbnail image to my sidebar in Woocommerce?

I'm using Woocommerce widgets to add the category list for my products in the sidebar of my website. Currently the categories are listed as worded lists. I would like the thumbnail image for each category to also be shown beside the word. I've managed to get the write the code below but it shows the category thumbnail in the centre of the page where the products are listed but I want the thumbnails in the sidebar beside the words. Can anybody help me figure out what I'm missing to achieve this? Thank you in advance!

HTML:

add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
        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="" />';
        }
}

Aucun commentaire:

Enregistrer un commentaire