I am trying to add multiple product categories -to display category thumbnail has product badge in catalog page
add_action ('woocommerce_before_shop_loop_item_title','alt_category_badge', 99);
add_action ('woocommerce_product_thumbnails','alt_category_badge', 100);
function alt_category_badge() {
global $product;
if ( is_product()){
global $post;
$brands_id = get_term_by('slug', 'sunglasses', 'product_cat');
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
if($term->parent === $brands_id->term_id) {
$category_name = $term->name;
$category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail);
if ( $image )
echo '<div class="brand-icon-logo sunglasses" ><img height="100%" width="35%" src="'.$image.'" alt="'.$category_name.' sunglasses online in dubai"></div>';
}
}
}
}
2
Answers
for specific categorys