I want to enable/disable free shipping based on my custom quote conditions, it works fine when free shipping is enabled from admin but I want it to work also when free shipping is disabled from admin. I tried the following solutions but none of them worked for me - How do I enable free shipping in backend only (for order entry)

How to programatically disable shipping method in magento


  • If you only provide shipping with an amount of 0, you can use shopping cart rules to achieve this. However it's applied to another shipping method than "free shipping". – luemic May 11 '16 at 6:44
  • I have added a custom column in quote table and I want to allow free shipping condition on that column's value. – Piyush May 11 '16 at 6:48

You need to rewrite the following class:


and modify the following method to:

 * Get carrier by its code
 * @param string $carrierCode
 * @param null|int $storeId
 * @return bool|Mage_Core_Model_Abstract
public function getCarrierByCode($carrierCode, $storeId = null)
    if (($carrierCode == 'freeshipping' && $customCondition) || !Mage::getStoreConfigFlag('carriers/'.$carrierCode.'/'.$this->_availabilityConfigField, $storeId)) {
        return false;
    $className = Mage::getStoreConfig('carriers/'.$carrierCode.'/model', $storeId);
    if (!$className) {
        return false;
    $obj = Mage::getModel($className);
    if ($storeId) {
    return $obj;

and you need to rewrite


(or better create a new carrier based on freeshipping)

and make the following changes:

 * FreeShipping Rates Collector
 * @param Mage_Shipping_Model_Rate_Request $request
 * @return Mage_Shipping_Model_Rate_Result
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    if (!$customCondition && !$this->getConfigFlag('active')) {
        return false;

    $result = Mage::getModel('shipping/rate_result');


    if (($request->getFreeShipping())
        || ($request->getBaseSubtotalInclTax() >=
    ) {
        $method = Mage::getModel('shipping/rate_result_method');





    return $result;
| improve this answer | |
  • Can You please explain what changes I have to made in rewrite files? – Piyush May 11 '16 at 9:37
  • In Mage_Shipping_Model_Shipping the first if condition is extended: if (($carrierCode == 'freeshipping' && $customCondition) ||.. which ignores the active flag if your custom condition is met. The same is applied to Mage_Shipping_Model_Carrier_Freeshipping in the first if if (!$customCondition &&.. which ignores the active flag if your custom condition is met. Please note that you need to implement the calculation of the condition for yourself, but that's another question. – luemic May 11 '16 at 11:09
  • Please let me know if there's some confusion left or mark this issue as solved. Thanks. – luemic May 12 '16 at 9:54
  • Thank You Michael , I Created a custom shipping method to meet the requirements. – Piyush May 12 '16 at 11:16

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.