1

I created a custom attribute for hiding add to cart button. I want to get attribute in the list.phtml file.

0

1 Answer 1

1

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..!!

8
  • 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
    – Priya
    Commented Aug 26, 2019 at 12:23
  • @kiya: can you add that error here? Commented Aug 26, 2019 at 12:24
  • 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
    – Priya
    Commented 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

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