Atish Bachhar

Full-Stack Magento 2 Developer

WordPress Developer

Shopify Developer

E-commerce Specialist

Atish Bachhar
Atish Bachhar
Atish Bachhar
Atish Bachhar

Full-Stack Magento 2 Developer

WordPress Developer

Shopify Developer

E-commerce Specialist

Blog Post

How to show custom attribute value on product page magento 2

May 11, 2022 Magento, PHP

Create a phtml file location app/design/frontend/vendor/theme/Magento_Catalog/templates/product/view/attr.phtml

here using this php code.

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
echo $product->getResource()->getAttribute('style_tips')->getFrontend()->getValue($product);
?>

Now upload xml code in catalog_product_view.xml

<referenceContainer name="product.info.main">
   <block class="Magento\Catalog\Block\Product\View" name="attr" template="product/view/attr.phtml" />
 </referenceContainer>
OR 
<referenceContainer name="content">
   <block class="Magento\Catalog\Block\Product\View" name="attr" template="product/view/attr.phtml" after="product.info.media" />
 </referenceContainer>

Now it will show your single product page

Tags:
2 Comments
  • James Brown 12:35 am July 13, 2021 Reply

    We can look for opportunities to turn processes into projects that have tangible outcomes. We can learn how to take joy in the things we create whether they take the form of a fleeting experience or an heirloom that will last for generations.

  • John Doe 12:36 am July 13, 2021 Reply

    Here is one of the few effective keys to the design problem: the ability of the designer to recognize as many of the constraints as possible;

Write a comment to John Doe Cancel Reply