You can delete the specific customer address by address id using the AddressRepositoryInterface interface.
Magento\Customer\Api\AddressRepositoryInterface contains the deleteById($addressId) function with pass first argument as address id to fetch specific customer address data.
<?php
namespace Rbj\Model\Address;
use Exception;
use Magento\Customer\Api\AddressRepositoryInterface;
class Delete
{
/**
* @var AddressRepositoryInterface
*/
private $addressRepository;
public function __construct(
AddressRepositoryInterface $addressRepository
) {
$this->addressRepository = $addressRepository;
}
/**
* @param int $addressId
*
* @return bool
*/
public function deleteCustomerAddressById(int $addressId)
{
$error = false;
try {
$this->addressRepository->deleteById($addressId);
} catch (Exception $e) {
$error = true;
throw new Exception($exception->getMessage());
}
return $error;
}
}
You can delete the specific customer address by the above function by passing the address id as the first argument.
$addressId = 10;
$address = $this->deleteCustomerAddressById($addressId);
