I'm trying to add the product category inside the product card in the woocommerce archive page. Right now it shows "Thumbnail" "Title" "Price" and "Add to cart button".
I'm using this function which should work if the variable "product" is set to the current product displayed.
My Question: Is there a way to get the queried Product in this variable?
Any help is appreciated.
<?php
// Hook after product title on archive page and run function "add_category()"
add_action('woocommerce_shop_loop_item_title','add_category');
// Define function "add_category()"
function add_category() {
// set var "cardcategory"
$cardcategory = $product->get_categories();
// create wrapping div
echo '<div class="category-carousel">';
// Get current category and change from plural to singular
// echo singular inside <p> element
if (strpos($cardcategory, 'Category_A_plural') !== false) {
echo '<p class="Category_A_class">Category A singular</p>';
}
if (strpos($cardcategory, 'Category_B_plural') !== false) {
echo '<p class="Category_B_class">Category B singular</p>';
}
// close wrapping div
echo '</div>';
}