0

Add track order link on Order History Page

  <block class="Magento\Shipping\Block\Tracking\Link" name="tracking-info-link" template="Magento_Shipping::tracking/link.phtml">
      <arguments>
          <argument name="label" xsi:type="string" translate="true">Track your order</argument>
      </arguments>
  </block>
7
  • With every order or only on the history page?
    – Sumit
    Sep 23, 2019 at 11:51
  • on histroy page
    – imtiazau
    Sep 23, 2019 at 13:31
  • what do you mean
    – imtiazau
    Sep 24, 2019 at 5:25
  • no when you login and click on my order magento opne this url /sales/order/history/ and show orders now i want add 1 more column track your order and want add lnk
    – imtiazau
    Sep 24, 2019 at 5:38
  • OK, so you have the link for the tracking the URL you want to add on the history page, right?
    – Sumit
    Sep 24, 2019 at 5:39

2 Answers 2

2

Copy the /vendor/magento/module-sales/view/frontend/templates/order/history.phtml file in your theme under /app/design/frontend/[Vendor]/[Theme]/Magento_Sales/templates/order/history.phtml with below content to add order tracking link.

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var \Magento\Sales\Block\Order\History $block */

?>
<?php $_orders = $block->getOrders(); ?>
<?= $block->getChildHtml('info') ?>
<?php if ($_orders && count($_orders)): ?>
    <div class="table-wrapper orders-history">
        <table class="data table table-order-items history" id="my-orders-table">
            <caption class="table-caption"><?= /* @escapeNotVerified */ __('Orders') ?></caption>
            <thead>
            <tr>
                <th scope="col" class="col id"><?= /* @escapeNotVerified */ __('Order #') ?></th>
                <th scope="col" class="col date"><?= /* @escapeNotVerified */ __('Date') ?></th>
                <?= /* @noEscape */ $block->getChildHtml('extra.column.header') ?>
                <th scope="col" class="col shipping"><?= /* @escapeNotVerified */ __('Ship To') ?></th>
                <th scope="col" class="col total"><?= /* @escapeNotVerified */ __('Order Total') ?></th>
                <th scope="col" class="col status"><?= /* @escapeNotVerified */ __('Status') ?></th>
                <th scope="col" class="col actions"><?= /* @escapeNotVerified */ __('Action') ?></th>
                <th scope="col" class="col actions">Track Order</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($_orders as $_order): ?>
                <tr>
                    <td data-th="<?= $block->escapeHtml(__('Order #')) ?>" class="col id"><?= /* @escapeNotVerified */ $_order->getRealOrderId() ?></td>
                    <td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date"><?= /* @escapeNotVerified */ $block->formatDate($_order->getCreatedAt()) ?></td>
                    <?php $extra = $block->getChildBlock('extra.container'); ?>
                    <?php if ($extra): ?>
                        <?php $extra->setOrder($_order); ?>
                        <?= /* @noEscape */ $extra->getChildHtml() ?>
                    <?php endif; ?>
                    <td data-th="<?= $block->escapeHtml(__('Ship To')) ?>" class="col shipping"><?= $_order->getShippingAddress() ? $block->escapeHtml($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
                    <td data-th="<?= $block->escapeHtml(__('Order Total')) ?>" class="col total"><?= /* @escapeNotVerified */ $_order->formatPrice($_order->getGrandTotal()) ?></td>
                    <td data-th="<?= $block->escapeHtml(__('Status')) ?>" class="col status"><?= /* @escapeNotVerified */ $_order->getStatusLabel() ?></td>
                    <td data-th="<?= $block->escapeHtml(__('Actions')) ?>" class="col actions">
                        <a href="<?= /* @escapeNotVerified */ $block->getViewUrl($_order) ?>" class="action view">
                            <span><?= /* @escapeNotVerified */ __('View Order') ?></span>
                        </a>
                        <?php if ($this->helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?>
                            <a href="#" data-post='<?php /* @escapeNotVerified */ echo
                            $this->helper(\Magento\Framework\Data\Helper\PostHelper::class)
                                ->getPostData($block->getReorderUrl($_order))
                            ?>' class="action order">
                                <span><?= /* @escapeNotVerified */ __('Reorder') ?></span>
                            </a>
                        <?php endif ?>
                    </td>
                    <td class="col actions">
                        <a href="#" class="action track" title="Track Your Order"
                           data-mage-init='{"popupWindow": {"windowURL":"<?= $this->helper('\Magento\Shipping\Helper\Data')->getTrackingPopupUrlBySalesModel($_order); ?>","windowName":"trackorder","width":800,"height":600,"left":0,"top":0,"resizable":1,"scrollbars":1}}'>
                            <span>Track Your Order</span>
                        </a>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php if ($block->getPagerHtml()): ?>
        <div class="order-products-toolbar toolbar bottom"><?= $block->getPagerHtml() ?></div>
    <?php endif ?>
<?php else: ?>
    <div class="message info empty"><span><?= /* @escapeNotVerified */ __('You have placed no orders.') ?></span></div>
<?php endif ?>

Flush the cache after the changes.

Hope it helps!!!

2
  • Have you tried this @imtiazau?
    – Sumit
    Sep 24, 2019 at 10:46
  • 1
    yes worked for me thanks
    – imtiazau
    Sep 25, 2019 at 5:03
0

You will need to create the file customer_account.xml in the path Vendor/Module/view/frontend/layout

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  <body>
      <referenceBlock name="customer_account_navigation">
           <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-custom">
              <arguments>
                 <argument name="path" xsi:type="string">routename/customer/index</argument>
                 <argument name="label" xsi:type="string">My Custom Tab </argument>
               </arguments>
           </block>
      </referenceBlock>
  </body>
</page>

For More Details add Custom Tab in Customer Account in Magento 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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