Make the email shipment tracking number a clickable link

You’ve probably noticed that when the emails for shipments are sent, the tracking number is included. Unfortunately though, it’s just plain text and isn’t a clickable link to actually track the shipment. The customer has to copy and paste and then go to the USPS, UPS, FEDEX or DHL site to get the tracking information .

Adding a few lines of code in a template will make the tracking number a clickable link that will bring them directly to the carriers site and display the tracking information for that shipment.

Basically what you’re doing is inserting a series of if statements between the $_item->getTitle() and the $_item->getNumber() that will display the proper link depending on the carrier code.

Now when your customer gets the shipment email, they can simply clink the link and get up-to-date tracking information!

Comments

By paul

In the ‘sales_flat_shipment_track’ table, look for the ‘carrier_code’ column to make sure the codes you’re using match the “if” criteria – you may have different codes than ‘ups’, ‘usps’ etc. If they’re different, you’ll need to modify the “if” criteria and the url for the tracking info.

You hit the nail on the head, Paul. It turns out our developer had created a ‘custom’ carrier as part of modification he did to enable our order processors to change shipping charges after a sales order has been created. And those are the orders that are not displaying a clickable tracking number. Thanks so much for all the assistance!

on October 21, 2014

By paul

In the ‘sales_flat_shipment_track’ table, look for the ‘carrier_code’ column – these should have the codes that have been assigned. You may find different ones than expected – modify/add the selection criteria as required

So I checked the mg_sales_flat_order table and ‘shipping_method’ (the only shipping-related field I could find) is ‘ups_GND’ for both the order in which the tracking link worked and the one that didn’t. Should I be looking in a different table (sorry for all the q’s; I’m obviously not a Magento programmer…)?

Thank’s for the reply. I’ll check it out on the back end and let you know how it goes!

on October 20, 2014

By paul

I’d probably check the carrier code to make sure it matches one of the criteria for assigning the link. Your automated method may be generating different codes. As it’s set up, it needs to be ‘ups’, ‘usps’. ‘fedex’, or ‘dhl’. If your automated method is generating any carrier code other than what’s defined (must match case too), you’ll need to add that code as part of the selection criteria.

if ($_item->getCarrierCode()==’usps’)
— change to additional criteria —
if (($_item->getCarrierCode()==’usps’) or ($_item->getCarrierCode()==’USPS’))

Weird. It worked perfectly when I first made the modification the other day and placed a test order. However, I just saw a Shipment email go through to a customer and the tracking number isn’t clickable anymore. I went back and checked track.phtml and the changes are still there. Any reason why it would work once and not again? The only difference I see is that I manually entered the shipping/tracking info into Admin when I successfully generated the first email; the email that came through without being clickable was from an order that I did not alter.

Magento Tips & Techniques

Magento is one of the leading E-Commerce platforms. The information provided in this site hopefully will help you with some "tweaks" to enhance the shopping experience or assist the administrator.

The posts are in no particular order but are added whenever I think of a tip, technique, code snippet or change that I think might be useful to the community.

I've only included 'hacks' that can be implemented by someone with a general Magento structure knowledge and basic php skills. More sophisticated Magento modifications are available from numerous sites and the Magento Knowledge base.