Several Important aspects make an online business successful like creating and implementing a marketing strategy, managing social media, writing emails, balancing the books, managing and ordering inventory and so on. And shipping may be at the lowest position on your list but its powerful enough to break your business. Because once customer orders the product, he or she is always wanting to know the shipping status until they receive their product hands on.
Sending such shipment tracking ID in your order email help your customer to track their shipment without contacting you or raising request. Unfortunately, Magento doesn’t bind order tracking code in the email that’s the reason why we have to code for adding shipment id in an email.
Here is the small piece of code that allows you to add Order tracking ID link in Shipping Email of Magento 2.
To do the same first we need to override this file:
Vendor\magento\module-sales\view\frontend\templates\email\shipment\track.phtml
by creating this path:
app\design\frontend\Theme\Yourtheme\Magento_Sales\templates\email\shipment\track.phtml
Now add the below code using for each loop.
<pre class="lang:default decode:true"><!--?php $trackurl = ''; if($_item->getCarrierCode() === 'fedex'){ $trackurl = 'https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber='.$_item->getNumber(); }elseif ($_item->getCarrierCode() === 'usps') { $trackurl = 'https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1='.$_item->getNumber(); }elseif ($_item->getCarrierCode() === 'ups') { $trackurl = 'https://wwwapps.ups.com/WebTracking/returnToDetails?tracknum='.$_item->getNumber(); } ?--><!--?= $block->escapeHtml($_item->getCarrierCode()) ?-->:</pre> <pre class="lang:default decode:true"></pre>
That’s it for today, Let us know if you are facing an issue while implementing this code by commenting below.
Happy Coding!
we not able to get anchor tag with href. just showing shipping tracking ID only in email. how can we get this with link. we also try with your above code.