Get an image for each Woocommerce product tag using Taxonomy Images plugin

admin

Administrator
Staff member
I'm developing a plugin for Woocommerce and I use the <a href="https://wordpress.org/plugins/taxonomy-images/" rel="nofollow noreferrer">Taxonomy Images</a> plugin to add image feature for Woocommerce product tag custom taxonomy.

Now I am trying to show for each product the product tag name with his coresponding image in a function. But may be I failed something because I see all tags and not only the tags for a specific product.

To get the product ID I have tried with
Code:
global $product;
but it's not working.

This is my code:

Code:
function woo_idoneo_tab_content() {

    $id = get_the_ID();

    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' =&gt; 'product_tag', 'id' =&gt; $id, ) );

        if ( ! empty( $terms ) ) {

            print '&lt;div class="container"&gt;';

            foreach ( (array) $terms as $term) {

            $url = get_term_link ($term-&gt;slug, 'product_tag' , $id);


            print '&lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"&gt;';
            print '&lt;div class="card"&gt;';
            print '&lt;div class="card-img-top"&gt;&lt;a href="'.$url.'"&gt;' . wp_get_attachment_image( $term-&gt;image_id, 'medium' ) . '&lt;/a&gt;&lt;/div&gt;';
            print '&lt;div class="card-body"&gt;';        
            print "&lt;h5 class='card-title'&gt;&lt;a class='btn btn-primary' href='{$url}'&gt;{$term-&gt;name}&lt;/a&gt;&lt;/h5&gt;";

            }

            print '&lt;/div&gt;';
            print '&lt;/div&gt;';
            print '&lt;/div&gt;';
        }
            print '&lt;/div&gt;';

    }
}

Any help is appreciated.