1

I want to show product custom attribute next to product in product detail page in magento2.2.5? Any help would be appreciated.

4
  • I have just added custom attribute from backend. But magento2 default shows custom attribute under details..But that also not showing in pdp page
    – Amy
    Commented Dec 4, 2018 at 15:33
  • what is attribute code and where you want to show ? could you please add a snapshot ?
    – Pawan
    Commented Dec 6, 2018 at 3:43
  • I want to show below the add to cart button in Product detail page. My attribute code is white_gold and rose_gold.
    – Amy
    Commented Dec 6, 2018 at 9:11
  • I have shared the screenshot. Please check it.
    – Amy
    Commented Dec 6, 2018 at 9:16

1 Answer 1

0

You need to create catalog_product_view.xml at:

Mage2Root/app/design/frontend/{Package}/{theme}/Magento_Catalog/layout/catalog_product_view.xml

with following code:

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="product.info.addtocart.additional">
        <block class="Magento\Catalog\Block\Product\View" name="gold" template="Magento_Catalog::gold.phtml"/>
    </referenceBlock>
</body>
</page>

Now create gold.phtml at:

Mage2Root/app/design/frontend/{Package}/{theme}/Magento_Catalog/templates/gold.phtml

with following code:

<?php $_product = $block->getProduct(); ?>
<?php //echo $_product->getName(); ?>
<?php echo $_product->getWhiteGold(); ?>
<?php echo $_product->getRoseGold(); ?>

Hope above will help!

1
  • Welcome Amy, glad to know :)
    – Pawan
    Commented Dec 10, 2018 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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