I am writing a custom shipping rates module, and I can’t seem to figure out how to get the estimate shipping Country ID.

I know how to get the Country id once the order has been created, but not for the estimate shipping portion of the checkout process

Any input is greatly appreciated!

For Magento 1.9 I used this



  • 1
    Hi did you got the solution for this question Oct 6, 2016 at 9:34

4 Answers 4


An interest fact about Magento2 That magento2 does not save shipping address address and billing address to quote until click on Place Order button at frontend.

Save Process

If you will check at database table quote_address during checkout,then you can understand.. Basically at browser local storage,Magento save shipping and billing address and save during click on place Order .

If you Digg on shipping estimation then you can understand that magento only need address attribute field country_id,region,region_id,city etc need for calculate the shipping rates .

At frontend checkout,Magento send address fields value from existing address or newly created address.


Magento 2.3.5

 private $cart;

public function __construct(
    \Magento\Checkout\Model\Cart $cart
) {
    $this->cart = $cart;

public function ()
    $estimated_country = $this->cart->getQuote()->getShippingAddress()->getCountryId();

Inject \Magento\Checkout\Model\Session in your constructor.

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

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


And then, we can get:



For the estimation shipping country, we can try:

/** @var \Magento\Quote\Api\Data\EstimateAddressInterface $estimatedAddress */
  • Thanks for replay but this not working in custom module model, Call \Magento\Checkout\Model\Session using objectManager $countryId = $checkoutSession->getQuote()->getShippingAddress()->getCountryId(); it's return NULL Sep 12, 2016 at 13:34
  • Currently, you login into your account? Sep 12, 2016 at 14:07
  • No i am not login into my account Sep 13, 2016 at 5:02
  • I have just updated my answer, we should try: Magento\Quote\Api\Data\EstimateAddressInterface. Sep 13, 2016 at 13:03
  • 1
    it also return null data with login or logout Sep 14, 2016 at 8:44

Instead of checkout session, I think you have to use checkout Cart

    protected $_checkoutCart;

    public function __construct(
        \Magento\Checkout\Model\Cart $checkoutCart
        $this->_checkoutCart = $checkoutCart;


And Then :

  • 1
    With out login it return null , i used $this->_checkoutCart->getQuote()->getShippingAddress()->getCountryId(); Sep 13, 2016 at 5:40

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.