How to Add Comment Text for Product Attributes in Magento 2
Magento 2 eCommerce platform facilitates customizing the default features depending on the business requirements. Default Magento is provided with helper text making it easier for the users to understand and get a better idea. Thus, adding comment text for product attributes in Magento 2 facilitates providing additional guidance regarding the input field such as how it will be used.
Almost all the CMS platforms are provided with a feature that may help to guide the users or provide them with the instructions. By offering them the instructions, it may help to boost the user experience of your online store. A comment appears below the product attribute section representing comments, instructions or special requests displayed while placing an order.
For example, an instruction is provided to add the name of extension. Thus, making it easier for the users to have a clear idea.
Thus, store owners can give a personal touch by adding a minor feature. This helper text is designed to guide the users, and default Magento contains a built-in attribute class that facilitates you to easily add comments or provide a note to the product users.
Method to Add Comment Text for Product Attributes in Magento 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<?php namespace Vendot\Extension\Setup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Catalog\Model\Product; use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; class InstallData implements InstallDataInterface { private $eavSetupFactory; public function __construct(EavSetupFactory $eavSetupFactory) { $this->eavSetupFactory = $eavSetupFactory; } public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); $eavSetup->addAttribute( Product::ENTITY, 'attribute_code', [ 'type' => 'text', 'label' => 'Custom Attribute', 'input' => 'text', 'required' => false, 'sort_order' => 10, 'global' => ScopedAttributeInterface::SCOPE_GLOBAL, 'group' => 'Custom Attribute', 'note' => 'Custom Attribute' // pass the value that you want as comment ] ); $setup->endSetup(); } } |
Please mention any doubts about the event in the comments section below. I’d be happy to help you.
Also, I’d be grateful if you could share the solution with the Magento community via social media.
Thank you.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How to Integrate Magento 2 Worldpay [Complete Guide]
Magento 2 WhatsApp Chat Extension [Complete Guide]
Next