I want to change the country in estimate shipping (cart page) programatically in my module (meaning user clicks on a button in footer on homepage and I change the shipping country on cart page for that session):

enter image description here

However it doesn't work if I do it with the session object.

// Magento\Checkout\Model\Session;

$quote = $this->session->getQuote()
$quote->getShippingAddress()->getCountryId() // returns GB which is right, but the sidebar on frontend is still showing US on refresh. 

3 Answers 3


This needs to be done with js. Something like:

var countryData = customerData.get('checkout-data');
            if (countryData()) {
                if (countryData().shippingAddressFromData) {
                    countryData().shippingAddressFromData.country_id = "GB";
                } else {
                    countryData().shippingAddressFromData = {};
                    countryData().shippingAddressFromData.country_id = "US;
                customerData.set('checkout-data', countryData());

This should be $quote->setShippingAddress()->getCountryId()->save();

  • not working, tried also $quote->setShippingAddress()->setCountryId("GB")->save() Apr 11, 2017 at 18:45

use this: $quote->getShippingAddress()->setCountryId("GB")->save()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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