How I get Current selected shipping address Id magneto 2.3.4

Viewed 1732

I Want to get selected shipping id on the checkout page.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
//$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 
$session = $objectManager->get('Magento\Checkout\Model\Session');
$quote = $session->getQuote();
$shippingMethod = $quote->getShippingAddress();
echo $addressId = $shippingMethod->getCustomerAddressId();

I try to get shipping address id but it always gives save id when I change bellow image from checkout https://drive.google.com/file/d/11N3SBaahNlugWzMw2ySAZHn4Yh4kQ64q/view

It not change the shipping id show same. How I get the current Selected shipping address Id?

1 Answers
protected $quoteRepository;

public function __construct (
   \Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
) {
    $this->quoteRepository = $quoteRepository;
}

$quote = $this->quoteRepository->get($quoteId);

$addressId = $quote->getCustomerAddressId();
Related