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.
Open: app/design/frontend/default/default/template/email/order/shipment/track.phtml
(if you don’t have the template listed, make a copy from app/design/frontend/base/default/template/email/order/shipment/track.phtml)
change the foreach loop so that it looks like this:
<?php $i=0; foreach ($_shipment->getAllTracks() as $_item): $i++ ?> <tr <?php echo $i%2?'bgcolor="#F6F6F6"':'' ?>> <td align="left" valign="top" style="padding:3px 9px"><?php echo $_item->getTitle() ?></td> <?php if ($_item->getCarrierCode()=='usps'): ?> <td align="center" valign="top" style="padding:3px 9px"><a href="https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=<?php echo $_item->getNumber() ?>"><?php echo $_item->getNumber() ?></a></td> <?php elseif ($_item->getCarrierCode()=='ups'): ?> <td align="center" valign="top" style="padding:3px 9px"><a href="http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=<?php echo $_item->getNumber() ?>"><?php echo $_item->getNumber() ?></a></td> <?php elseif ($_item->getCarrierCode()=='dhl'): ?> <td align="center" valign="top" style="padding:3px 9px"><a href="http://www.dhl-usa.com/content/us/en/express/tracking.shtml?brand=DHL&AWB=<?php echo $_item->getNumber() ?>"><?php echo $_item->getNumber() ?></a></td> <?php elseif ($_item->getCarrierCode()=='fedex'): ?> <td align="center" valign="top" style="padding:3px 9px"><a href="https://www.fedex.com/fedextrack/?tracknumbers=<?php echo $_item->getNumber() ?>"><?php echo $_item->getNumber() ?></a></td> <?php else: ?> <td align="center" valign="top" style="padding:3px 9px"><?php echo $_item->getNumber() ?></td> <?php endif; ?> </tr> <?php endforeach ?>
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
Leave a Reply
You must be logged in to post a comment.
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.
Sadly, it didn’t work for me.
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!
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!
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.
Paul,
A+ work! Thank you for figuring this simple item out. Works like a charm for our transactional emails. Keep up the great work.
Frank