0

I want to Get Tracking id when shipping the order, For it, I use "sales_order_shipment_save_after" Observer. And I try but I got the blank array. My code is

$shipment = $observer->getEvent()->getShipment();               
$order = $shipment->getOrder();
$shipmentCollection = $order->getShipmentsCollection(); 

$tracksCollection = $order->getTracksCollection();

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

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

}

I also try other solution which is given in the old post but I am not got any result. I am also try $observer->getEvent()->getTrack(); but also got blank in data.

0

Try with below code.

//Get shipment details.
$shipment = $observer->getEvent()->getShipment();

//Get shipment tracking info.
$trackingNumbers = array();
foreach ($shipment->getAllTracks() as $track) {
 $trackingNumbers[] = $track->getNumber();
 };
 echo '<pre>', print_r($trackingNumbers);exit;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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