I'm trying to show all available sizes for one product on list.phtml
I've set up a custom attribute size_age (id:142) but when I try use the code
$attributeLabel = $customer->getResource() ->getAttribute('size_age') ->getFrontend() ->getAttribute() ->getFrontendLabel();
I get this error:
Fatal error: Call to a member function getResource() on null
UPDATE:
thank you for your answers. I changed the code to:
$attributeLabel = $_product->getResource() ->getAttribute('size_age') ->getFrontend() ->getAttribute() ->getFrontendLabel();
I dont have any error right now.
But I dont get any output. I'm trying to echo all available sizes for the product.
1 Answer 1
You can get the value of custom attribute using following:
$attribute = $_product->getResource()->getAttribute('custom_attribute_code');
if ($attribute) {
echo $attribute_value = $attribute->getFrontend()->getValue($_product);
}
Explore related questions
See similar questions with these tags.
$customervariable ? Shouldn't it be a$productvariable ?$_product, NOT$customer