You can create new module and override that file otherwise you do that using custom theme as well.
I'll show you here how can we override template file using custom module.
Please create Vendor name directory first, and move into that and create another directory Module.
Then you need to create registration.php
file here.
app/code/Vendor/Module/registration.php
Content for this file is ..
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
After that please create one more directory there etc
here and add module.xml
file there..
app/code/Vendor/Module/etc/module.xml
Content for this file is ..
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0" />
</config>
After that please create view
directory there and move into that and create frontend
move into that.
create layout
directory and add customer_account_index.xml
this file there..
app/code/Vendor/Module/view/frontend/layout/customer_account_index.xml
Content for this file is ..
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<referenceBlock name="customer_account_dashboard_info">
<action method="setTemplate">
<argument name="template" xsi:type="string">Vendor_Module::account/dashboard/info.phtml</argument>
</action>
</referenceBlock>
</referenceContainer>
</body>
</page>
After creating this file please go back once and create templates
directory here
app/code/Vendor/Module/view/frontend/templates
and add info.phtml
file here in this path
app/code/Vendor/Module/view/frontend/templates/account/dashboard/info.phtml
Content for this file is ..
<div class="block block-dashboard-info">
<div class="block-title"><strong><?= $block->escapeHtml(__('Account Information')) ?></strong></div>
<div class="block-content">
<div class="box box-information">
<strong class="box-title">
<span><?= $block->escapeHtml(__('Contact Information')) ?></span>
</strong>
<div class="box-content">
<p>
<?= $block->escapeHtml($block->getName()) ?><br>
<?= $block->escapeHtml($block->getCustomer()->getEmail()) ?><br>
</p>
<?= $block->getChildHtml('customer.account.dashboard.info.extra'); ?>
</div>
<div class="box-actions">
<a class="action edit" href="<?= $block->escapeUrl($block->getUrl('customer/account/edit')) ?>">
<span><?= $block->escapeHtml(__('Edit')) ?></span>
</a>
<a href="<?= $block->escapeUrl($block->getChangePasswordUrl()) ?>" class="action change-password">
<?= $block->escapeHtml(__('Change Password')) ?>
</a>
</div>
</div>
<?php if ($block->isNewsletterEnabled()) : ?>
<div class="box box-newsletter">
<strong class="box-title">
<span><?= $block->escapeHtml(__('Newsletters')) ?></span>
</strong>
<div class="box-content">
<p>
<?php if ($block->getIsSubscribed()) : ?>
<?= $block->escapeHtml(__('You are subscribed to "General Subscription".')) ?>
<?php else : ?>
<?= $block->escapeHtml(__('You aren\'t subscribed to our newsletter.')) ?>
<?php endif; ?>
</p>
</div>
<div class="box-actions">
<a class="action edit" href="<?= $block->escapeUrl($block->getUrl('newsletter/manage')) ?>"><span><?= $block->escapeHtml(__('Edit')) ?></span></a>
</div>
</div>
<?php endif; ?>
</div>
</div>
In this template file you can change anything whatever you want there.
You can override your block here
For that you need to create di.xml
file here
app/code/Vendor/Module/etc/di.xml
Content for this file is ...
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Customer\Block\Account\Dashboard\Info" type="Vendor\Module\Block\Account\Dashboard\Info" />
</config>
Then after you need to create Info.php
file here
app/code/Vendor/Module/Block/Account/Dashboard/Info.php
Content for this file is ..
<?php
namespace Vendor\Module\Block\Account\Dashboard;
use Magento\Framework\Exception\NoSuchEntityException;
class Info extends \Magento\Customer\Block\Account\Dashboard\Info
{
public function myCustomFunction(){
return true;
}
}
Here I've created my custom function and override default Info.php
file we do not need to copy whole file just extend parent class and you can create your custom functions there.
Hope this will help you!