It is well known that customizing the core Magento 2 functionality is a bad coding practice. Once you upgrade the Magento version, your efforts are in vain. Hence, it is advisable to override a function, class or file, as per the requirement.
Here, I’ll show you how to override a phtml file using a custom module in Magento 2.
There are two methods to do so as mentioned below:
Methods to Override a phtml file using a custom module in Magento 2:
- Create file registration.php at app/code/Vendor/Extension/ folder1<!--?xml version="1.0"?-->
- Create file customer_account_create.xml at app/code/Vendor/Extension/view/frontend/layout/ folder123456<!--?xml version="1.0"?-->Vendor_Extension::form/register.phtml
now you need to create register.phtml at location app/code/Vendor/Extension/view/frontend/templates/form/
The above example shows how to override a phtml file for product stock status. The default functionality to show out of stock is overridden to display an image.
Follow any of the above method suitable to you.
Please share your doubts on the topic in the Comments section below. I’d be happy to help.
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.