Answers.Body: <p>You could also use <code>$order-&gt;getShippingAddress()</code> which is even shorter! :)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-02T14:34:35.550Z
Answers.LastActivityDate: 2022-06-02T14:34:35.550Z
Answers.UserDisplayName: iamkeir
Answers.Body: <p>You can use the <a href="https://docs.craftcms.com/commerce/api/v3/craft-commerce-services-addresses.html#public-methods" rel="noreferrer">Addresses</a> service to get the shipping address:</p>
  <pre><code>$address = craft\commerce\Plugin::getInstance()-&gt;getAddresses()-&gt;getAddressById($order-&gt;shippingAddressId);
  </code></pre>
  <p>This is the more direct method to get the address, and it's a bit shorter to type too!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-07T12:55:22.293Z
Answers.LastActivityDate: 2022-04-07T12:55:22.293Z
Answers.UserDisplayName: Martin Spain
Body: <p>I'm trying to add an address column to my orders index but I'm having trouble correctly getting the actual address.</p>
  <p>From my code below, when I dump on <code>$orderShippingAddress</code> I get the ID of a valid address. But when I dump on <code>$address</code> I get <code>null</code>.</p>
  <p>Can anyone spot where I'm going wrong? For reference, I was working from here: <a href="https://craftcms.com/docs/commerce/3.x/addresses.html#get-current-customer-address-by-id" rel="nofollow noreferrer">https://craftcms.com/docs/commerce/3.x/addresses.html#get-current-customer-address-by-id</a></p>
  <pre><code>Event::on(
      Order::class,
      Order::EVENT_REGISTER_TABLE_ATTRIBUTES,
      function (RegisterElementTableAttributesEvent $event) {
          $event-&gt;tableAttributes['address'] = ['label' =&gt; 'Address'];
      }
  );  
  
  Event::on(
      Order::class,
      Order::EVENT_SET_TABLE_ATTRIBUTE_HTML,
      function (SetElementTableAttributeHtmlEvent $event) {
          $order = $event-&gt;sender;
          $orderShippingAddress = $order-&gt;shippingAddressId;
          $address = craft\commerce\Plugin::getInstance()-&gt;getCustomers()-&gt;getCustomer()-&gt;getAddressById($order-&gt;shippingAddressId);
          dump($shippingAddress);
          if ($event-&gt;attribute === 'address') {
               $event-&gt;html = $address;
          }
      }
  );
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-07T09:06:33.513Z
Comments.Text: What do you get if you just use the `addresses` service? `$address = craft\commerce\Plugin::getInstance()->getAddresses()->getAddressById($order->shippingAddressId);`
Comments.UserDisplayName: Martin Spain
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-07T09:55:24.430Z
Comments.Text: Nice one! That does it!
Comments.UserDisplayName: supazu
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-07T12:37:36.307Z
Comments.Text: @MartinSpain if you add that as an answer I'll mark it accepted
Comments.UserDisplayName: supazu
Tags: <plugin-craftcommerce>
Title: Get order shipping address in module
ThreadText: # Get order shipping address in module
  
  (Asked by: username_0 on 2022-04-07)
  
  I'm trying to add an address column to my orders index but I'm having trouble correctly getting the actual address.
  
  From my code below, when I dump on `$orderShippingAddress` I get the ID of a valid address. But when I dump on `$address` I get `null`.
  
  Can anyone spot where I'm going wrong? For reference, I was working from here: <https://craftcms.com/docs/commerce/3.x/addresses.html#get-current-customer-address-by-id>
  
  ```
  Event::on(
      Order::class,
      Order::EVENT_REGISTER_TABLE_ATTRIBUTES,
      function (RegisterElementTableAttributesEvent $event) {
          $event->tableAttributes['address'] = ['label' => 'Address'];
      }
  );  
  
  Event::on(
      Order::class,
      Order::EVENT_SET_TABLE_ATTRIBUTE_HTML,
      function (SetElementTableAttributeHtmlEvent $event) {
          $order = $event->sender;
          $orderShippingAddress = $order->shippingAddressId;
          $address = craft\commerce\Plugin::getInstance()->getCustomers()->getCustomer()->getAddressById($order->shippingAddressId);
          dump($shippingAddress);
          if ($event->attribute === 'address') {
               $event->html = $address;
          }
      }
  );
  
  ```
  
  **Tags:** plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: What do you get if you just use the `addresses` service? `$address = craft\commerce\Plugin::getInstance()->getAddresses()->getAddressById($order->shippingAddressId);`  
  > **username_0**: Nice one! That does it!  
  > **username_0**: @username_1 if you add that as an answer I'll mark it accepted  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-04-07. Score: 6 | Accepted answer
  
  You can use the [Addresses](https://docs.craftcms.com/commerce/api/v3/craft-commerce-services-addresses.html#public-methods) service to get the shipping address:
  
  ```
  $address = craft\commerce\Plugin::getInstance()->getAddresses()->getAddressById($order->shippingAddressId);
  
  ```
  
  This is the more direct method to get the address, and it's a bit shorter to type too!
  
  
  ---
  
  ### Answer by username_2 on 2022-06-02. Score: 2
  
  You could also use `$order->getShippingAddress()` which is even shorter! :)
  
  
  ---
  
  