I want to show product custom attribute next to product in product detail page in magento2.2.5? Any help would be appreciated.
-
I have just added custom attribute from backend. But magento2 default shows custom attribute under details..But that also not showing in pdp page– AmyCommented Dec 4, 2018 at 15:33
-
what is attribute code and where you want to show ? could you please add a snapshot ?– PawanCommented 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.– AmyCommented Dec 6, 2018 at 9:11
-
I have shared the screenshot. Please check it.– AmyCommented Dec 6, 2018 at 9:16
Add a comment
|
1 Answer
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!