I'm using Drupal 8 with the module Commerce and I have an issue with the customer address.

I'm developing an export custom module in D8, and I'm stuck trying to load the profile (to access billing and shipping address) of a customer.

I'm not able to access this data from the custom module. And there is no documentation about the address pluggin ( https://www.drupal.org/project/address )

I have tried to load the order and the user data but there is no relevant field that helps me to achieve this.

Can anyone give me a hint?

Thanks in advance.

3 Answers 3


you can try get profile by order and can try the code below:

$order_id =1;
$entityManager = \Drupal::entityTypeManager();
$order = $entityManager->getStorage('commerce_order')->load($order_id);

get address by field billing_profile

$address = $order->billing_profile->entity->address->getValue();

Starting from the order, this may help you:

if ($this->order->hasField('shipments') && !$this->order->get('shipments')->isEmpty() ) {
  $order_shipments = $this->order->get('shipments')->referencedEntities();
  $order_shipment = reset($order_shipments);
  $shipment_profile = $order_shipment->getShippingProfile();
  // Prepare shipment information.
  $addressValues = $shipment_profile->address->getValue();
  $shipment['locality'] = $addressValues[0]['locality'];
  $shipment['administrative_area'] = $addressValues[0]['administrative_area'];
  $shipment['postal_code'] = $addressValues[0]['postal_code'];

Since the customer profile is a content entity you can access customer profile information by using the entityTypeManager() function.

$entity_manager = \Drupal::entityTypeManager();
$profile = $entity_manager->getStorage('profile')->load($profile_id);
  • 1
    It's worth noting that if you don't know the profile id and you're looking for the user profiles, try using $entity_manager->getStorage('profile')->loadByUser($account, 'customer', TRUE); and there's also loadMultipleByUser() and loadDefaultByUser(). Jun 21, 2018 at 16:18

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.