I created a custom attribute for hiding add to cart button. I want to get attribute in the list.phtml file.
1 Answer
We can get custom attribute Label & Value like below:
Attribute Value
<?php /* @escapeNotVerified */ echo $_product->getResource()->getAttribute('your_attribute_name')->getFrontend()->getValue($_product); ?>
Label
$address =$_product->getResource()->getAttribute('your_attribute_name')->getStoreLabel();
I hope it will help..!!
-
I have already use this code but error generated....Uncaught Error: Call to a member function getResource() on null in view/frontend/templates/product/list.phtml– PriyaCommented Aug 26, 2019 at 12:23
-
-
Fatal error: Uncaught Error: Call to a member function getResource() on null in /var/www/html/magento2.3/app/code/Vendor/Mymodule/view/frontend/templates/product/list.phtml– PriyaCommented Aug 26, 2019 at 12:28
-
@kiya : can you add your list.phtml file's code here? Commented Aug 26, 2019 at 12:30
-
@kiya: Make sure “Visible on Product View Page on Front-end” and “Used in Product Listing” options under storefront Properties are set to Yes. Can you verify above settings for your custom attribute once? Commented Aug 26, 2019 at 12:32