I'm trying to create a product attribute, but I don't want it to sit under the more info tab. I would like to almost be its own block and sit under the 'Add to cart' button.

How would I go about doing this?


Add the below lines in your theme layout file app/design/frontend/Vendor/ThemeName/Magento_Catalog/layout/catalog_product_view.xml

<move element="custom" destination="content" after="product.info.addtocart" />
<container name="custom">
        <block class="Magento\Catalog\Block\Product\View" name="custom.sec" as="customsec" template="product/view/custom.phtml" />
<!-- if you want to remove more info tab add this line otherwise ignore -->
<referenceContainer name="product.attributes" remove="true" />

Get attribute value in app/design/frontend/Vendor/ThemeName/Magento_Catalog/templates/product/view/custom.phtml

$_product = $block->getProduct();
$value = $_product->getResource()->getAttribute('c_address')->getFrontend()->getValue($_product); //atttribute value
$lable = $_product->getResource()->getAttribute('c_address')->getStoreLabel(); //attribute lable

echo $value.' : '.$lable;

note: c_address is my custom attribute

If you want to custmize more info tab, override the below template


you can find the declaration in app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml

<block class="Magento\Catalog\Block\Product\View\Attributes" name="product.attributes" as="additional" template="product/view/attributes.phtml" group="detailed_info">
                    <argument translate="true" name="title" xsi:type="string">More Information</argument>
  • sorry where should custom.phtml sit? Edit: sorry seen where it should go – Mark Aug 22 '16 at 13:58
  • Thats worked now I just need to get it to sit in the right place as its not quite bellow the add to cart button. Oh and your just missing a '.' before $lable Thanks! – Mark Aug 22 '16 at 14:10
  • updated my answer @Mark – Bilal Usean Aug 22 '16 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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