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)




Do the changes according to your need.

STEP 2 :

Now we need to create a Plugin class.



namespace Bajaj\Customer\Plugin\Customer\Block\Widget;

class Telephone
    public function beforeToHtml(\Magento\Customer\Block\Widget\Telephone $subject)

STEP 3 :

Update di.xml 


<?xml version="1.0"?>
<config xmlns:xsi=""
    <type name="Magento\Customer\Block\Widget\Telephone">
        <plugin name="module_customer_block_widget_telephone_override_template"


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



Thank you 🙏 !

Leave a Reply

Your email address will not be published. Required fields are marked *