{"id":1552,"date":"2021-01-28T06:04:14","date_gmt":"2021-01-28T06:04:14","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/add-custom-text-or-html-on-product-page-using-plugin-in-magento-2\/"},"modified":"2025-07-17T10:05:38","modified_gmt":"2025-07-17T04:35:38","slug":"add-custom-text-or-html-on-product-page-using-plugin-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-custom-text-or-html-on-product-page-using-plugin-in-magento-2\/","title":{"rendered":"How to Add Custom Text or HTML on Product Page Using Plugin in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">An E-commerce store\u2019s core strength is the product it offers. The presentation of the product can make or break a sale.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A product page is where the potential customers spent their maximum time before making the purchase. Also, it is the product page that gets shared the maximum number of times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hence, the product page must be designed strategically to attract more customers and improve sales. The default\u00a0Magento 2\u00a0product page may fall short to fulfill the business requirements related to the product page design.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One may want to customize the product page by adding custom links, notification messages, additional functionalities, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, you may want to offer the gift wrapping facility at an additional cost along with the product purchase, or you may want to display a custom notification bar.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It can be done easily with the programmatic solution to&nbsp;<em><strong>add custom text or HTML on product page using plugin in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below solution to add any custom checkboxes, links, messages, etc. in your product page using plugin in Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enhance the product page design and enjoy higher conversion rates!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Add Custom Text or HTML on Product Page Using Plugin in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create<strong>&nbsp;di.xml<\/strong>&nbsp;at&nbsp;<strong>app\/code\/Vendor\/Module\/etc\/frontend&nbsp;<\/strong>and use the below code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\">\n    &lt;type name=\"Magento\\Catalog\\Block\\Product\\View\">\n        &lt;plugin name=\"custom-text\" type=\"Vendor\\Module\\Plugin\\Catalog\\Block\\Product\\View\"\/>\n    &lt;\/type>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<strong>View.php&nbsp;<\/strong>at&nbsp;<strong>app\/code\/Vendor\/Module\/Plugin\/Catalog\/Block\/Product&nbsp;<\/strong>and follow the below code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Module\\Plugin\\Catalog\\Block\\Product;\nuse Magento\\Catalog\\Block\\Product\\View as ProductView;\nclass View\n{\n    private $displayBlocks = ['product.info.addtocart'];\n    \/\/ you can add layout references as per your need to display like: product.info.price, product.info.review, etc.\n    public function afterToHtml(ProductView $subject, $html)\n    {\n        if (in_array($subject->getNameInLayout(), $this->displayBlocks)) {\n            return $html . '&lt;div class=\"custom-text\">Test 1&lt;\/div>';\n        }\n        return $html;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, I\u2019ve used&nbsp;<strong>product.info.addtocart&nbsp;<\/strong>to display custom text under the \u2018Add to Cart\u2019 button.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are customizing the product page, you can use a&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/how-to-use-a-custom-price-template-in-magento-2\/\">custom price template in Magento 2<\/a>&nbsp;to change the way prices are displayed on it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An E-commerce store\u2019s core strength is the product it offers. The presentation of the product can make or break a sale. A product page is&#8230;<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1552","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1552"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1552\/revisions"}],"predecessor-version":[{"id":14529,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1552\/revisions\/14529"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}