Magento 2 load multiselect attribute values in product list
-
15-04-2021 - |
Question
I am trying to load multiple values of Color attribute in product list phtml file with this code:
<?php echo __('Color: ') . $_product->getAttributeText('color'); ?>
But I get array error:
Notice: Array to string conversion
Any help please? This is magento 2.4 version
Solution
Try the following way:
$color = $_product->getAttributeText('color');
if ($color) {
if (is_array($color)) {
echo implode(',', $color);
} else {
echo $color;
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange