{"id":1100,"date":"2020-07-05T05:38:58","date_gmt":"2020-07-05T05:38:58","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/07\/05\/get-tracking-information-from-shipment-in-magento-2\/"},"modified":"2025-07-21T17:14:19","modified_gmt":"2025-07-21T11:44:19","slug":"get-tracking-information-from-shipment-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-tracking-information-from-shipment-in-magento-2\/","title":{"rendered":"How to Get Tracking Information From Shipment in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A customer-centric mindset leads to success in business. More now than ever, owing to the competition in E-commerce, enhancing the customers\u2019 shopping experience is a never-ending process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And my job is to help the readers who are Magento 2 store owners, in implementing features that can improve the customer experience of their store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And as a part of it, today, I am posting a programmatic solution to&nbsp;<em><strong>get tracking information from shipment in Magento 2<\/strong><\/em>. To get it done you need to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/add-tracking-number-to-the-current-order-shipment-in-magento-2\/\">add tracking number to current order shipment in Magento 2<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use this solution in your Magento 2 store when you notify your customers about the order placement. For example, you are sending an email or SMS to notify the customers about their recent order placed and you need to add the carrier name and the tracking number of the item to be delivered. The below method will help you get the tracking information from the order\/shipment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Doing so will be easier for customers to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-custom-carrier-trackers-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">track the order in Magento 2<\/a>. Everyone is excited about receiving the items ordered online, it is a general human tendency. Acting upon this human emotion to level up your customer experience game is a smart thing to do!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this solution, I\u2019ll be using the shipment details entered from the backend as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2020\/07\/ExnFFoa-1024x212.png\" alt=\"New shipment\" class=\"wp-image-9509\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Obtain these details from the shipment and then use it along with the Email or SMS that you send for notifying the customers about successful order placement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to get tracking information from shipment in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add below code in your&nbsp;<em><strong>events.xml<\/strong><\/em>&nbsp;file at&nbsp;<strong><strong>Vendor\\Extension\\etc<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Event\/etc\/events.xsd\">\n    &lt;event name=\"sales_order_shipment_save_after\">\n        &lt;observer name=\"track_shipment\" instance=\"Vendor\\Extension\\Observer\\Shipment\" \/>\n    &lt;\/event>\n &lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create new&nbsp;<em><strong>Shipment.php<\/strong><\/em>&nbsp;file at&nbsp;<strong><strong>Vendor\\Extension\\Observer<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Extension\\Observer;\nuse Magento\\Framework\\Event\\ObserverInterface;\nclass Shipment implements ObserverInterface\n{\n    public function execute(\\Magento\\Framework\\Event\\Observer $observer)\n    {\n        try {\n            $shipment = $observer->getEvent()->getShipment();\n            $tracksCollection = $shipment->getTracksCollection();\n            foreach ($tracksCollection->getItems() as $track) {\n                $trackNumber = $track->getTrackNumber();\n                $carrierName = $track->getTitle();\n            }\n        } catch (\\Exception $e) {\n        }\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do not forget to share the post with fellow Magento 2 store owners via social media and help them in enhancing the customer experience of the store! Contributing to making E-commerce a better place to shop is a nice thing to do after all!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer-centric mindset leads to success in business. More now than ever, owing to the competition in E-commerce, enhancing the customers\u2019 shopping experience is a&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1100","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1100"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1100\/revisions"}],"predecessor-version":[{"id":18817,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1100\/revisions\/18817"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}