How to display Woocommerce Category image?
To display a category image in WooCommerce, you can use the woocommerce_subcategory_thumbnail hook in your theme's functions.php file.
To display a category image in WooCommerce, you can use the woocommerce_subcategory_thumbnail hook in your theme's functions.php file (preferably in a child theme). This hook is used to display the category image on the shop page, and it takes the category object as a parameter. Here is an example of how to use this hook:
Example of displaying Woocommerce category image
<?php
function display_category_image($category)
{
$thumbnail_id = get_term_meta($category->term_id, 'thumbnail_id', true);
if ($thumbnail_id) {
echo wp_get_attachment_image($thumbnail_id, 'thumbnail');
}
}
remove_action('woocommerce_subcategory_thumbnail', 'woocommerce_subcategory_thumbnail', 10);
add_action('woocommerce_subcategory_thumbnail', 'display_category_image', 10);
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Learn object oriented PHP</div>
This code will display the category image on the shop page, next to the category name. Note: This code snippet assumes you have set the category image while creating/editing the category in the backend. After adding the code, clear your WooCommerce and browser cache to see the changes.