How do I fetch the user ID from the shipping profile? I'm trying to get the User ID from Shipping Profile in Drupal Commerce using the following code, but eventually, $entity->getOwnerId() is returning me NULL in any case, if it's an authenticated user or admin it's giving me 0 as the UID.

function mymodule_entity_insert(EntityInterface $entity) {
    if ($entity-&gt;getEntityTypeId() === 'profile') {
        /** @var \Drupal\user\Entity\User $user */
        $user = User::load($entity-&gt;getOwnerId());
    }
}
Shipping and billing profiles don't have a user ID, they are always anonymous because they belong to the parent entity (order/shipment), not the user.

Only address book profiles have user IDs.