Each order has store_id , when it is entered through the administrator, it will be either 0 (for admin storage) or null.
if ($order->getStoreId()) {
Do not use getStore() , as this will not always reliably return an admin storage object.
It does not work with the latest versions of Magento. (see comment)
clockworkgeek
source share