How to run a custom PHP code when a backend user have created a shipment document for an order?

I have created a custom shipping module, it’s possible to make orders with it.
Now I need to figure out how to hook on to the saving of a delivery of the order.

I basically need to run custom code when admin have created a shipment from the order.
How do you do that?

The \Magento\Sales\Model\Order\Shipment class, as any other \Magento\Framework\Model\AbstractModel descendant, fires some events on saving:

Use them to run your custom PHP code.

1 Like