How to get the last order programmatically?

Use the \Magento\Checkout\Model\Session::getLastRealOrder() method.

See also:

This don’t work for me when my caches are enable… :confused:

It could be because you execute the method on an empty checkout session.