7

How can I get the shipment tracking information from shipment or order object in magento2. Following ways doesn't work for me.

$shipment->getTrackingInfo();

$order->getTrackingInfoByOrder();

2 Answers 2

12

To get the shipping tracking numbers, use the following code.

$tracksCollection = $order->getTracksCollection();

foreach ($tracksCollection->getItems() as $track) {

     $trackNumbers[] = $track->getTrackNumber();

}

This will return an array of all shipment tracking numbers.

2

To get track collection object

$order->getTracksCollection()->fetchItem();
$order->getTracksCollection()->fetchItem()->getTitle();
$order->getTracksCollection()->fetchItem()->getTrackNumber(); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.