I am using this plugin
https://woocommerce.com/products/custom-product-tag-image/
To add images to my tags.
I’d like to display a list of tags with images. I’ve tried so many approaches but nothing yet.
Here’s my code which outputs a list of tags but no images.
<?php $taxonomyName = "product_tag";
$terms = get_terms(array('taxonomy' => 'product_tag', 'hide_empty' => false)); ?>
<?php foreach ( $terms as $term ) { ?>
<div class="item" >
<?php
$thumb_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
$term_img = wp_get_attachment_url( $thumb_id );
?>
<img src="<?php echo $term_img; ?>" />
<a href="<?php echo get_term_link( $term->term_id, 'product_tag' ); ?> " rel="tag"><?php echo $term->name; ?></a>
</div>
<?php } ?>
Suggestions?
2
Answers
The code below is what worked for me as
woocommerce_get_term_meta
is deprecated andthumbnail_id
doesn't exist anymore:You can use WC
get_woocommerce_term_meta()
and WPwp_get_attachment_url()
. check below code.