Feb 12, 2012
kalpesh

Magento: Show “track your order” in frontend – My Orders

It is always required for the customer to track their order. The shipping carriers can be anything: Aramex, Bluedart, DHL, First Flight, Federal Express, etc.. Navigate to My Account and place a button in My Orders section there “Track Order”. Paste the code below to link it to tracking popup that you can also see in backend Shipments area.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
if($_order->hasShipments()) {
    $show = true;
    foreach($_order->getTracksCollection() as $k=>$v) {                            
        if($v['carrier_code'] == 'custom' || $v['carrier_code'] == '')
            $show = false;
    }
    if($show) {?>
        <span class="separator2">&nbsp;</span>

        <a class="askTrackBtn" href="javascript:;" onclick="popWin('<?php echo Mage::helper('shipping/data')->getTrackingPopUpUrlByOrderId($_order->getId()) ?>', 'tracking the order', 'scrollbars=yes,width=800,height=600,resizable=yes');return false;"><span><?php echo $this->__('Track Order') ?></span></a>
       <?php 
    }
}?>

15 Comments

  • Hiya, which file is this change made iin?

    • How do I edit the track my order link? I am done with the website but this link is going no where. Please help on how to edit this page.

  • @Jeff, it should be in the file where you want your customer to track their shipment,
    app/design/frontend/default/default/template/sales/order/view.phtml

  • Any idea how to put that link into the header? Or in top.links?

    • You can place it in header, but the thing is will you get order details in header? Also, header is included in all the pages, your customers would not like to see “Track your Order” in header when you are in homepage or other pages irrelevant to order section right?

  • nice….

    • Hey Jeff
      put this code in

      yourtemplate/sales/order/history.phtml

      Cheers!

  • i place in “history.phtml” and also in ” view.phtml” but it was not getting

  • i want to insert tracking link to magento from csv, can you please give me any suggestion how can i do it

  • this never worked….i tried both in history and view. Nothing showed. I wanted to show the pop up link along with all the orders.

    Can you tell me what i am doing wrong?

  • gr8 its working thanks 🙂

  • i am also not unable to see the code in frontend but i have added the code in “app/design/frontend/default/default/template/sales/order/view.phtml” and “yourtemplate/sales/order/history.phtml” ………get able to see ….tried many times .

    thanks

  • Its way better to use Magento’s own method to check if the order has shipment attached.

    getTracksCollection()->count()) : ?>
    <a href="#" onclick="popWin('helper(‘shipping’)->getTrackingPopupUrlBySalesModel($_order) ?>’,’trackorder’,’top=0,left=0,width=800,height=600,resizable=yes,scrollbars=yes’); return false;” title=”quoteEscape($this->__(‘Track your order’)) ?>”>__(‘Track your order’) ?>

    • How to use this code for magento 2.please help me.

  • How to use this code for magento 2,Please help me.

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Recognition

Magento top 50 contributors

Honor