Magento 1.8 – How to Set Default Shipping Method and Country

magento-1.8shippingshipping-methods

How can I set my default shipping method in the shopping cart to the country where my store is?

For instance, I want to set the default shipping method to the UK when the customer are on the shopping cart page.

By Magento default, you have to select your country where you want to ship your order to. Then you have to hit the button 'Get a quote' for the 'Estimate Shipping and Tax'. But I want to skip this step by setting the default shipping method to the UK automatically when you are on this page.

Is it possible?

I tried with this code below,

$shippingAddress = $this->getQuote()->getShippingAddress();
$shippingAddress->setCountryId('UK')->setShippingMethod('tablerate_bestway')->save();

But you have to refresh the shopping cart page for a couple of times before it sets the shipping method to the UK.

I need it set the shipping method to the UK as soon as you land on the shopping cart page though, is it possible?

Best Answer

I used this method just so I could change the css on the <select> element but it makes it easier to "filter" countries and what not as well, which could help you.

Go to /app/design/frontend/THEME_NAME/default/template/checkout/cart/shipping.phtml

Try replacing:

<?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>

With this:

<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadByStore()->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
    <select name="country_id" id="country" class="validate-select">
        <option value="GB">United Kingdom</option>
        <?php foreach($_countries as $_country): ?>
            if($_country['value']=="GB")
            {
                continue
            }
            else
            {
                <option value="<?php echo $_country['value'] ?>">
                    <?php echo $_country['label'] ?>
                </option>
            }
        <?php endforeach; ?>
    </select>
<?php endif; ?>
Related Topic