For that you have to work with observer and used checkout_cart_save_after
event and paste this below code in the observer file that you created:
private $_shippingCode = 'flatrate_flatrate';
private $_country = 'GB';
public function addShipping($params = null) {
if (Mage::registry('checkout_addShipping')) {
Mage::unregister('checkout_addShipping');
return;
}
Mage::register('checkout_addShipping',true);
$cart = Mage::getSingleton('checkout/cart');
//zend_debug::dump($cart->getData());exit;
$quote = $cart->getQuote();
if ($quote->getCouponCode() != '') {
$c = Mage::getResourceModel('salesrule/rule_collection');
$c->getSelect()->where("code=?", $quote->getCouponCode());
foreach ($c->getItems() as $item) { $coupon = $item; }
if ($coupon->getSimpleFreeShipping() > 0) {
$quote->getShippingAddress()->setShippingMethod($this->_shippingCode)->save();
return true;
}
}
try {
//$method = $quote->getShippingAddress()->getShippingMethod();
//if ($method) return; // don't overwrite what's already there if we have one set already
if ($quote->getShippingAddress()->getCountryId() == '') {
$quote->getShippingAddress()->setCountryId($this->_country);
}
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getShippingAddress()->collectShippingRates();
$rates = $quote->getShippingAddress()->getAllShippingRates();
$allowed_rates = array();
foreach ($rates as $rate) {
array_push($allowed_rates,$rate->getCode());
}
if (!in_array($this->_shippingCode,$allowed_rates) && count($allowed_rates) > 0) {
$shippingCode = $allowed_rates[0];
}
//zend_debug::dump(Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal());exit;
//if(Mage::helper('checkout')->getQuote()->getData('subtotal')<=49){
$totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
$finaltotal = $totals["subtotal"]->getValue();
// zend_debug::dump($sample);exit;
//zend_debug::dump($finaltotal);exit;
if($finaltotal<=49){
if (!empty($shippingCode)) {
$address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
if ($address->getCountryId() == '') $address->setCountryId($this->_country);
if ($address->getCity() == '') $address->setCity('');
if ($address->getPostcode() == '') $address->setPostcode('');
if ($address->getRegionId() == '') $address->setRegionId('');
if ($address->getRegion() == '') $address->setRegion('');
$address->setShippingMethod($this->_shippingCode)->setCollectShippingRates(true);
Mage::getSingleton('checkout/session')->getQuote()->save();
} else {
$address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
if ($address->getCountryId() == '') $address->setCountryId($this->_country);
if ($address->getCity() == '') $address->setCity('');
if ($address->getPostcode() == '') $address->setPostcode('');
if ($address->getRegionId() == '') $address->setRegionId('');
if ($address->getRegion() == '') $address->setRegion('');
$address->setShippingMethod($this->_shippingCode)->setCollectShippingRates(true);
Mage::getSingleton('checkout/session')->getQuote()->save();
}
}
else{
if (!empty($shippingCode)) {
$address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
if ($address->getCountryId() == '') $address->setCountryId($this->_country);
if ($address->getCity() == '') $address->setCity('');
if ($address->getPostcode() == '') $address->setPostcode('');
if ($address->getRegionId() == '') $address->setRegionId('');
if ($address->getRegion() == '') $address->setRegion('');
$address->setShippingMethod('freeshipping_freeshipping')->setCollectShippingRates(true);
Mage::getSingleton('checkout/session')->getQuote()->save();
} else {
$address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
if ($address->getCountryId() == '') $address->setCountryId($this->_country);
if ($address->getCity() == '') $address->setCity('');
if ($address->getPostcode() == '') $address->setPostcode('');
if ($address->getRegionId() == '') $address->setRegionId('');
if ($address->getRegion() == '') $address->setRegion('');
$address->setShippingMethod('freeshipping_freeshipping')->setCollectShippingRates(true);
Mage::getSingleton('checkout/session')->getQuote()->save();
}
}
Mage::getSingleton('checkout/session')->resetCheckout();
}
catch (Mage_Core_Exception $e) {
Mage::getSingleton('checkout/session')->addError($e->getMessage());
}
catch (Exception $e) {
Mage::getSingleton('checkout/session')->addException($e, Mage::helper('checkout')->__('Load customer quote error'));
}
}
It worked for me when checkout cart subtotal is less than 49.
If so it displays free shipping otherwise displays flat rate charge.