I want to show product custom attribute next to product in product detail page in magento2.2.5? Any help would be appreciated.
Asked
Active
Viewed 177 times
1
-
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 Dec 04 '18 at 15:33
-
what is attribute code and where you want to show ? could you please add a snapshot ? – Pawan Dec 06 '18 at 03: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 Dec 06 '18 at 09:11
-
I have shared the screenshot. Please check it. – Amy Dec 06 '18 at 09:16
1 Answers
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!
Pawan
- 5,856
- 2
- 14
- 36