Magento 2 – How to Display Custom Product Attributes on Product Page

attributesmagento-2.1product-attribute

I have some attributes that I want to go above the "Add to Cart" button. How can I achieve this?

I followed this tutorial but that didn't work for me -> http://www.dckap.com/blog/display-custom-attribute-value-product-viewlist-page-magento-2/

I am using Magento version 2.1.8

Best Answer

Create attr.phtml file and call all your attributes inside that file.

app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/attr.phtml

add your attribute code

<?php echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($block->getProduct(), $block->getProduct()->getAttributeCode(), 'attribute_code'); ?>

Inside your xml file

app/design/frontend/Vendor/theme/Magento_Catalog/layout/catalog_product_view.xml

<referenceBlock name="product.info.main">
    <block class="Magento\Catalog\Block\Product\View" name="attr" template="product/view/attr.phtml" />
</referenceBlock>

after that move your attr block where ever you want.

for example,

<move element="attr" destination="product.info.main" before="product.info.price" />

let me know if you need any help.

Related Topic