Customizing the core Magento 2 functionality is a bad coding practice. The solution is to override a phtml file using a custom module in Magento 2.
Methods to Override a phtml file using a custom module in Magento 2:
1. with plugin
2. with XML
Learn the implementation of both the methods at https://meetanshi.com/blog/override-phtml-file-using-custom-module-in-magento-2/