Echo product attribute values on catalog or product pages.

Submitted by deeperdata - 3 years ago

I use the following script often to debug my custom sorts or to display attribute values onto various product and catalog/category pages. Pretty straight forward.

// Use this method if attribute isn't already registered
    $attribute = $_product->getResource()->getAttribute('your_attribute_code');
    if ($attribute) {
        echo "<p>" . $attribute_value = $attribute ->getFrontend()->getValue($_product) . "</p>";
    }
    
// Use this method if your attribute IS registered
    echo "<p>" . $_product->getAttributeText('your_attribute_code') . "</p>";

// Should work from the catalog/product/list.phtml page or view.phtml page.
affiliate_link
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean