0

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

0

Try the following way:


$color = $_product->getAttributeText('color');
        if ($color) {
            if (is_array($color)) {
                echo implode(',', $color);
            } else {
                echo $color;
            }
        }
1
  • Working great! Thank you so much! – G. G. Mar 8 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.