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

  1. By paul

  2. By David

  3. By paul

  4. By David

  5. By David

  6. By paul

  7. By David

  8. By Frank

Leave a Reply