I need to get checkout form data before placing order, but I am only getting default shipping address below is the code snippet I tried:


$customerId = $this->_customerSession->getCustomer()->getId();  
$customerInfo = $this->customerFactory->create()->load($customerId);
$customerAddress = $customerInfo->getDefaultShippiingAddress();

getshipiingAddress() method returning null

I want to get form data for logged in and guest customer both.

2 Answers 2


I found solution for this and posting here to help otheres:

            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 

            $billingAddress = $cart->getQuote()->getBillingAddress();
            echo '<pre>'; print_r($billingAddress->getData()); echo '</pre>';

            $shippingAddress = $cart->getQuote()->getShippingAddress();
            echo '<pre>'; print_r($shippingAddress->getData()); echo '</pre>';

You can get cart data using checkout session class.

Use this code in your class:

 * @var \Magento\Checkout\Model\Session
protected $_checkoutSession;

public function __construct(
    \Magento\Checkout\Model\Session $checkoutSession
    $this->_checkoutSession = $checkoutSession;


And following code to get quote data.

$this->_checkoutSession->getQuote(); // get quote data
$this->_checkoutSession->getQuote()->getShippingAddress(); //get shipping address

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.