I would like to display the current category in the product name in woocommerce. What only applies for variable products.
The code below is partly working, but need some reforming:
1 - to be applied for only for variable products.
2 - to show the current category that the viewer is in not the main product category.
remove_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10);
function loop_title() {
global $post;?>
<div class="col-xl-3 col-md-3 col-sm-3">
<h2><a href="<?php the_permalink(); ?>" class="feed-item-baslik"><?php the_title(); ?> <?php
$terms = get_the_terms( $post->ID, 'product_cat' );
if ( $terms && ! is_wp_error( $terms ) ) :
if ( ! empty( $terms ) ) {
echo $terms[0]->name;
}?>
<?php endif;?></a></h2>
</div>
<?php }
add_action('woocommerce_shop_loop_item_title', 'loop_title', 10);