0

How to display custom attributes on Product Details page near product name?.

Here Manufacturer Name and Manufacturer Number is custom attributes. which value i want to show on Product Details page near product name.

enter image description here

Using this code view/frontend/layout/catalog_product_view.xml

<?xml version="1.0" encoding="UTF-8"?>
<page 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.details">
        <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.demo" template="Custom_ProductAttribute::product/view/attribute.phtml" after="-">
            <arguments>
                <argument name="at_call" xsi:type="string">getDemoLink</argument>
                <argument name="at_code" xsi:type="string">manufacturer_name</argument>
                <argument name="css_class" xsi:type="string">manufacturer_name</argument>
                <argument name="at_label" xsi:type="string">Manufacturer Name</argument>
                <argument name="add_attribute" xsi:type="string">itemprop="manufacturer_name"</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>

view/frontend/templates/product/view/attribute.phtml

<?php

 $manufacturerName = $_product->getResource()->getAttribute('manufacturer_name');
echo $manufacturerName->getFrontend()->getValue($_product);

?>

enter image description here

1 Answer 1

1

You can use below code to display custom attribute on PDP

Manufacturer Name :

$manufacturerName = $_product->getResource()->getAttribute('manufacturer_name'); 
echo $manufacturerName->getFrontend()->getValue($_product);

Manufacturer No :

$manufacturerNo = $_product->getResource()->getAttribute('manufacturer_no'); 
echo $manufacturerNo->getFrontend()->getValue($_product);
8
  • I edit the question can you please check is it right?
    – Vivek
    Feb 18, 2021 at 13:45
  • You have to add in .phtml not .xml Feb 18, 2021 at 13:47
  • here i added view/frontend/templates/product/view/attribute.phtml
    – Vivek
    Feb 18, 2021 at 13:47
  • Can you guide me steps please.
    – Vivek
    Feb 18, 2021 at 13:48
  • 1
    Yes i understand but can you please share me steps please
    – Vivek
    Feb 18, 2021 at 14:03

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.