How to Override a Customer Module Widget Templates in Magento 2 using Plugin

If you are building a module and you encounter a block that cannot be referenced by name then you probably need to create a plugin to overwrite the template. This can be achieved in three simple steps.

STEP 1 :

Copy telephone.phtml template to your custom module (in my case it’s Bajaj_Customer)

/vendor/magento/module-customer/view/frontend/templates/widget/telephone.phtml

to

/app/code/Bajaj/Customer/view/frontend/templates/widget/telephone.phtml

Do the changes according to your need.

STEP 2 :

Now we need to create a Plugin class.

/app/code/Bajaj/Customer/Plugin/Customer/Block/Widget/Telephone.php

STEP 3 :

Update di.xml 

/app/code/Bajaj/Customer/etc/di.xml

 

Similarly you can override any templates defined in the widget folder.

customer-module-widget-template

 

Thank you 🙏 !