search
Log In
Welcome to Blogiestools Ask, a blogging community where beginner and professional bloggers come to seek answers from other bloggers’ experiences.

You can ask questions related to starting a blog, monetizing a blog, marketing a blog, managing a blog, fixing a problem, the best web tech tools to use, etc.

Register or log in to ask or answer questions.

Ask a Question

0 votes
I need to display a featured image on my WooCommerce product category pages
in WordPress Problems
edited by

1 Answer

0 votes

To display a featured image in WooCommerce Product Category or archive pages, add the code below to your WordPress theme's function.php file.  

/**

* Display category image on WooCommerce category archive

*/

add_action( 'woocommerce_archive_description', 'woocommerce_category_featured_image', 2 );

function woocommerce_category_featured_image() {

    if ( is_product_category() ){

        global $wp_query;

        $cat = $wp_query->get_queried_object();

        $thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );

        $image = wp_get_attachment_url( $thumbnail_id );

        if ( $image ) {

            echo '<img src="' . $image . '" alt="' . $cat->name . '" />';

        }

    }

}
 

What this code does is that it detects if there is any featured thumbnail image added in the product category page and displays it.

Your WooCommerce theme must have an option to add image in the product category page.

15.4k points
edited by

Related questions

0 votes
1 answer
I am looking for ways to disable lazy load in a specific image in visual composer
asked Nov 4, 2021 in WordPress Problems anonymous
0 votes
1 answer
I want to modify the WooCommerce checkout loading spinner gif and use my custom icon and text
asked Nov 8, 2021 in WordPress Problems anonymous
1 vote
1 answer
I want to allow guest customers to checkout in WooCommerce with specific email domains. I do not want accounts to be registered during checkout with disposable emails.
asked Nov 8, 2021 in WordPress Problems anonymous
0 votes
1 answer
I have a digital marketplace running on WooCommerce. How do I notify vendors when an admin rejects their submitted product?
asked Nov 8, 2021 in WordPress Problems anonymous
0 votes
1 answer
I need a code to change WooCommerce add cart button text without installing a plugin
asked Nov 8, 2021 in WordPress Problems anonymous