Magento – Get product attribute programatically

custom-attributesmagento2

I have a custom attribute called 'Color', which is a select box,

I have a instance of the product, and I want to get the selected value of my field 'Color'. The problem is when I try to do it its always returning null.

This is my code:

$product->getCustomAttribute('prj_color')

This is always null. But if I try to get a different field, which is not a multivalued field, a textbox for example, I can get the value normally.

I'm using Magento 2.1.5. Someone know whats going on?

Best Answer

get VAlue

<?php /* @escapeNotVerified */ echo $_product->getResource()->getAttribute('c_address')->getFron‌​tend()->getValue($_p‌​roduct); ?>

LABEL

$address =$_product->getResource()->getAttribute('c_address')->getStoreLabel();

Check this file ::Magento/Catalog/templates/product/view/attribute.phtml

Related Topic