Is their any way we can override email/shipment/track.phtml ? in module ?

created layout file


<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="tracking">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Mod_Sales::email/shipment/track.phtml</argument>

created template file


Any thoughts what can be the issue ?

  • I have added this layout file but its not working – devhs Feb 22 at 6:28
  • any thoughts ?? – devhs Feb 22 at 6:45
  • I am checking for you. Please give me few mins. – ZealousWeb Feb 22 at 6:46
  • I have added correct answer for you. Please approve and upvote my answer. Thanks! Enjoy coding. – ZealousWeb Feb 22 at 6:52

I have checked your code , you have taken wrong referenceBlock.

Please use below code in your xml file (sales_email_order_shipment_track.xml)

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="sales.order.email.shipment.track">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">PackageName_Module::email/shipment/track.phtml</argument>

Please create file track.phtml under path PackageName/Module/view/frontend/templates/email/shipment/

Put below code :-

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
<?php /* @var \Magento\Framework\View\Element\Template $block */ ?>
<?php $_shipment = $block->getShipment() ?>
/* @var \Magento\Sales\Model\Order $_order */
$_order = $block->getOrder() ?>
<?php if ($_shipment && $_order) : ?>
    <?php $trackCollection = $_order->getTracksCollection($_shipment->getId()) ?>
    <?php if ($trackCollection) : ?>
        <br />
        <table class="shipment-track">
                <th><?= $block->escapeHtml(__('Shipped By dhwani')) ?></th>
                <th><?= $block->escapeHtml(__('Tracking Number')) ?></th>
            <?php foreach ($trackCollection as $_item) : ?>
                    <td><?= $block->escapeHtml($_item->getTitle()) ?>:</td>
                        <a href="<?= $block->escapeUrl($block->getTrackingUrl()->getUrl($_item)) ?>" target="_blank">
                            <?= $block->escapeHtml($_item->getNumber()) ?>
            <?php endforeach ?>
    <?php endif; ?>
<?php endif; ?>

In above code i have changed title like below to check it is working or not.

<th><?= $block->escapeHtml(__('Shipped By dhwani')) ?>

And i have got below output in email:-


  • I have checked this its not working, the module phtml is not getting called – devhs Feb 22 at 7:05
  • I have checked it practically and it is working. – ZealousWeb Feb 22 at 7:07
  • can you please send me that module ? – devhs Feb 22 at 7:09
  • Sure, Also i have updated my code here. Please check once. If still it does not work for you, i will send a module. – ZealousWeb Feb 22 at 7:11
  • Sure thanks, let me check – devhs Feb 22 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.