Go with get_the_term_list()
this will give you an output a comma-separated list of links to product categories:
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li class="product-list__item">
<a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a>
<?php echo get_the_term_list( get_the_ID(), 'product_cat', '', ', ' ); ?>
</li>
<?php endwhile; ?>
When you are in 'the loop' (i.e. between $loop->the_post();
and endwhile
) you don't need to pass an ID to get_permalink()
, simply use the_permalink()
.
Please fix the last missing > from the opening anchor tag,