cancel
Showing results for 
Search instead for 
Did you mean: 

Display UPC and MFR on Product Page

Display UPC and MFR on Product Page

I am looking for a way to display the MFR# and UPC# on the product page just the way it shows the SKU#. Currently the page does show the SKU. I would like to have the UPC and MFR show close to the SKU. I already have the attribute fields in the backend for products. Also not all my items have a UPC# and MFR# and when the field is empty in the backend for that product it won't show on the product page.

7 REPLIES 7

Re: Display UPC and MFR on Product Page

@Media Bug 

 

Add the snippet of code below to the following file in your custom theme(override below file to your theme catalog_product_view.xml):

Magento_Catalog/layout/catalog_product_view.xml

<referenceContainer name="columns.top">
      <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.customattribute" template="Magento_Catalog::product/view/attribute.phtml" after="product.main.title">
              <arguments>
                  <argument name="at_call" xsi:type="string">{at call goes here e.g. getCustomAtribute}</argument>
                  <argument name="at_code" xsi:type="string">{attribute code goes here}</argument>
                  <argument name="at_label" xsi:type="string">default</argument>
                  <argument name="add_attribute" xsi:type="string">itemprop="{attribute code goes here}"</argument>
              </arguments>
      </block>
</referenceContainer>

Then flush your caches and the attribute should appear.

Manish Mittal
https://www.manishmittal.com/

Re: Display UPC and MFR on Product Page

Hi @Media Bug 

 

Go to the Magento Admin -> Stores -> Attributes, and here you have two important sections:

 - Product

 - Attribute Set

 

In Product section, you have to create attribute called UPC.

In Attribute Set, you have to edit each single attribute set, and to move UPC attribute from "Unassigned Attributes" group to the group where you want to display it.

 

It may help you!
Problem Solved? Please click on 'Kudos' & Accept as Solution!

Problem solved? Click Accept as Solution!

Re: Display UPC and MFR on Product Page

I have the attributes named and assigned correctly. Also have each UPC code listed for each product in the backend. Just cannot figure out how to get it to display on the product page. I have tried the above snipit and caused my page to have errors. I had to revert to the original file Catalog_product_view.xml.

 

Re: Display UPC and MFR on Product Page

@Media Bug 

 

Can you share what error you are getting after adding above script. Thanks

Manish Mittal
https://www.manishmittal.com/

Re: Display UPC and MFR on Product Page

Fatal error: Uncaught Error: Call to a member function getStoreLabel() on bool in C:\xampp\htdocs\magento234\vendor\magento\module-catalog\view\frontend\templates\product\view\attribute.phtml:37 Stack trace: #0 C:\xampp\htdocs\magento234\vendor\magento\framework\View\TemplateEngine\Php.php(59): include() #1 C:\xampp\htdocs\magento234\vendor\magento\framework\Interception\Interceptor.php(58): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\View\Description), 'C:/xampp/htdocs...', Array) #2 C:\xampp\htdocs\magento234\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent('render', Array) #3 C:\xampp\htdocs\magento234\vendor\magento\framework\Interception\Interceptor.php(153): Magento\Framework\View\TemplateEngine\Php\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Block\Product\View\Description), 'C:/xampp/htdocs...', Array) #4 C:\xampp\htdocs\magento234\generated\code\Magento\Framewo in C:\xampp\htdocs\magento234\vendor\magento\module-catalog\view\frontend\templates\product\view\attribute.phtml on line 37

Re: Display UPC and MFR on Product Page

@Media Bug 

 

Just override catalog\view\frontend\templates\product\view\attribute.phtml and add condition on line 37:

 

check if (!is_null($attributevalue)) {

Might be you are adding that attribute value is blank so it is throwing this error.

Manish Mittal
https://www.manishmittal.com/

Re: Display UPC and MFR on Product Page

Hi Manish, I have the same problem, I need to take the data of 5 attributes that are already created and add below the SKU, I am a very intermediate user of magento 2, I am using the Codazon Fastest theme, can you help me?

 

I need to add these 5 attributes. These are their codes.

1 - upc
2 - weight
3 - expiration_date
4 - country_of_manufacture
5 - manufacturer

Sometimes this attribute can be empty. When it is empty I would like it not to appear.add_attributes-.jpg