0

I am trying to figure how to add an attribute (UPC) to display just under the SKU on the my product page. I have tried in the past with no such luck. I really need this to work. I have found several different post for this to work and of them worked. The closet one I have found was from this link:

Display Custom Attribute Multiplace Place on Products Details Page Magento 2

Problem I am having is the UPC Code from the attribute does display in the right place, however the Label (UPC:) does not show, only the UPC #. I used the same code below:

You can display custom attributes by creating block after the sku block in catalog_product_view

Create catalog_product_view.xml in "app\design\frontend\VENDOR\THEME\Magento_Catalog\layout\catalog_product_view.xml"

Create custom_attr.phtml file in "app\design\frontend\VENDOR\THEME\Magento_Catalog\templates\product\view\custom_attr.phtml" getProduct(); ?> getData('upc_code') ?>

Sample Screen Shot

4
  • Can you share your phtml code, please? May 24, 2021 at 6:02
  • Not 100% sure what phtml code you need to see, however this is the custom_attr.phtml file that was created per the post I found. Create custom_attr.phtml file in "app\design\frontend\VENDOR\THEME\Magento_Catalog\templates\product\view\custom_attr.phtml" <?php $_product = $this->getProduct(); ?><div class="product attribute"> <div class="value"><?php echo $_product->getData('upc_code') ?></div> </div>
    – Troy B.
    May 24, 2021 at 12:46
  • Replace this $_product->getData('upc_code') by $_product->load($_product->getId())->getUpcCode() May 24, 2021 at 16:49
  • Changed the code per your suggestion and nothing changed, stayed the same
    – Troy B.
    May 25, 2021 at 11:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.