Thank you very much @lorro, it works!
The only problem now is that array_shift
excludes the name of the other categories
from the function.
ex.
product 1 (category:red)
product 2 (categories:green,red,yellow)
$single_cat = array_shift( $product_cats );
switch ($single_cat->name) {
case 'red': // nb no break;
case 'blue':
echo '<span class="categoria">'.$single_cat->name.'</span>';
break;
default:
// no action for anything other than red or blue
}
I can see the name of the category just in the first product,
so I presume that I have to change array_shift
in something else, or am I wrong?