---
title: "How to Get Default Billing and Shipping Address by Customer ID in Magento 2"
url: "https://magecomp.com/blog/get-default-billing-and-shipping-address-by-customer-id-magento-2/"
date: "2023-09-22T15:03:17+00:00"
modified: "2025-02-13T08:55:17+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 341
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Learn How to Get Default Billing and Shipping Address by Customer ID in Magento 2"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to add a Custom tab in Admin Sales Order view Magento 2?"
    url: "https://magecomp.com/blog/add-custom-tab-admin-sales-order-view-magento-2/"
  - title: "How to Add Extra New Column on Shopping Cart Page of Magento 2?"
    url: "https://magecomp.com/blog/add-extra-new-column-on-shopping-cart-page-magento-2/"
  - title: "How to Set up Magento 2 Cron in Xampp for Windows"
    url: "https://magecomp.com/blog/set-up-magento-2-cron-in-xampp-windows/"
---

# How to Get Default Billing and Shipping Address by Customer ID in Magento 2

_Published: September 22, 2023_  
_Author: Dhiren Vasoya_  

![How to Get Default Billing and Shipping Address by Customer ID in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/09/How-to-Get-Default-Billing-and-Shipping-Address-by-Customer-ID-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

Today, I have come up with a solution to get default billing and shipping addresses by customer ID in Magento 2.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-4.webp)](https://magecomp.com/services/hire-magento-programmer/)

Magento 2 allows customers to have multiple billing and shipping addresses associated with their account. Each of these addresses can be used during the checkout process, providing flexibility for customers with different shipping or billing requirements.
Learn – [**How to Configure Multiple Shipping Addresses in Magento 2**](https://magecomp.com/blog/configure-multiple-addresses-shipping-magento-2/).
Customers can also have default billing and shipping addresses set in their customer accounts. Customers can have only one default billing and one default shipping address at a time. These addresses are convenient for returning customers as they can quickly select them during the checkout process, but customers can always choose to enter a new address if needed.
Let’s find out How to Get Default Billing and Shipping Address by Customer ID in Magento 2.
## [![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-4.webp)](https://magecomp.com/magento-malware-removal.html)

## Steps to Get Default Billing and Shipping Address by Customer ID in Magento 2:
**Step 1:** Create a block file at the given path below.
**{{magento_root}}\app\code\Vendor\Extension\Block\AddressBook.php**

Now add the code as follows.
```
<?php

namespace VendorExtensionBlock;

class AddressBook extends MagentoFrameworkViewElementTemplate
{
    protected $accountManagement;

    public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        MagentoCustomerApiAccountManagementInterface $accountManagement,
        array $data = []
    ) {
        $this->accountManagement = $accountManagement;
        parent::__construct($context, $data);
    }

    public function getDefaultShippingAddress($customerId)
    {
        try {
            $address = $this->accountManagement->getDefaultShippingAddress($customerId);
        } catch (NoSuchEntityException $e) {
            return __('You have not added default shipping address.');
        }
        return $address;
    }

    public function getDefaultBillingAddress($customerId)
    {
        try {
            $address = $this->accountManagement->getDefaultBillingAddress($customerId);
        } catch (NoSuchEntityException $e) {
            return __('You have not added default billing address.');
        }
        return $address;
    }
}
```

## Conclusion:
This way, you can get the default billing and shipping address by customer ID in Magento 2. If you have any doubts about the above method or if you face any errors, connect with me through the comment section. Share the tutorial with your friends and stay in touch with us so that you do not miss out on any important Magento solution from us.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-3.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/get-default-billing-and-shipping-address-by-customer-id-magento-2/](https://magecomp.com/blog/get-default-billing-and-shipping-address-by-customer-id-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-28 08:44:15 UTC_  
