1

Using Magento 2.3.2.

Following on from my other question about changing the product description to another attribute, I would also like to display a new attribute - 'website name' as the product name on the product page rather than the default 'name'.

Because we sell on ebay our existing product names are stuffed with keywords. We would like 'website name' to be simpler and cleaner.

Any help would be gratefully received.

asked Oct 5, 2020 at 10:54

1 Answer 1

1

I actually did something similar recently. I added a product attribute with id short_product_name

Then I added that into template file: app/design/frontend/PACKAGE/THEME/Magento_Catalog/templates/product/list.phtml

There I first added this code to get the data from the product attribute:

<?php /* Short Product Name*/
$short_product_name = $_product->getResource()->getAttribute('short_product_name');
$short_product_nameValue = $short_product_name->getFrontend()->getValue($_product);?>

Then I used this to display the short name version in frontend:

<a class="product-item-link" href="<?php echo $_product->getProductUrl() ?>">
<?php if ($short_product_nameValue) { ?>
 <?php echo $short_product_nameValue; ?>
<?php } else {
 echo $_helper->productAttribute($_product, $_product->getName(), 'name');
} ?>
</a>
answered Oct 5, 2020 at 14:17
1
  • I only needed to use that attribute on product list page, but maybe you can use this on product page too. Commented Oct 5, 2020 at 14:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.