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.
1 Answer 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>
-
I only needed to use that attribute on product list page, but maybe you can use this on product page too.Webninja– Webninja2020年10月05日 14:47:03 +00:00Commented Oct 5, 2020 at 14:47