How to set default shipping address of the customer Magento 2?

Set Default shipping address id of the customer in Magento 2 using Address Repository Interface.

You required Customer Id to set shipping address and address id you want to assign it.

First, load the existing address by the getById method of the address repository interface with the set customer.

$address->setIsDefaultShipping(true) set the current address id to default address for the given customer.

Call method by required parameter,

When you successfully run the method, you can see the updated address details from the My Account section of the frontend.

  • Database Section:
    customer_entity table stores the address id in the default_shipping column from the database.