1

i have created one product custom attribute name -> 'is-buynowbutton-show' and i want to get that attribute value in product list page to show buy now based on product setting.

Does anyone suggest me how i can get product custom attributes value in product list page?

1
  • +1 for answer acceptance :) – Shoaib Munir Sep 3 '20 at 5:34
1

First open attribute on admin

Store -> Attributes -> Products

Then open your desired attribute is-buynowbutton-show, open tab Storefront Properties

In this tab you will find option "Used in Product Listing" make sure it is set to Yes

Now in your list phtml file you can use attribute like this

$_product->getData("is-buynowbutton-show");

Note: A piece of advice, do not use dash (-) always use underscore (_) in attribute code. so that you can be able to use it like this $_product->getIsBuynowbuttonShow();

1
  • 1
    Thanks @Shoaib Working Great !!! – Sanjay Shiyal Sep 3 '20 at 5:24
0

In product list page you will get the foreach loop with product colection. Each product of this loop is product object as $_product.

The you will get this value of this product custom attribute as $_product->getData('is-buynowbutton-show')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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