Getting Enabled Shipping Methods From Magento


The below script can be used to print out a list of all enabled shipping methods on a Magento instance.

To get a list of shipping methods for a different store, change the store code on line 33.

When you run the script, you should get output which looks similar to this:

Outputting a list of all enabled shipping methods for store code: default.
Array
(
    [flatrate_flatrate] => Array
        (
            [title] => Fixed
            [carrier] => Flat Rate
        )
    [freeshipping_freeshipping] => Array
        (
            [title] => Free
            [carrier] => Free Shipping
        )
)

Shipping Methods Script

Save this script in the file shell/autoship_get_shipping_methods.php in your Magento instance folder and run it from your Magento base folder with the following command.

php shell/autoship_get_shipping_methods.php

<?php
/**
 * Subscribe Pro - Subscriptions Management Extension
 *
 * PHP version 5
 *
 * LICENSE: This source file is subject to commercial source code license of SUBSCRIBE PRO INC.
 *
 * @category  SFC
 * @package   SFC_Autoship
 * @author    Garth Brantley <[email protected]>
 * @copyright 2009-2014 SUBSCRIBE PRO INC. All Rights Reserved.
 * @license   http://www.subscribepro.com/terms-of-service/ Subscribe Pro Terms of Service
 * @link      http://www.subscribepro.com/
 *
 */

require 'app/Mage.php';

if (!Mage::isInstalled()) {
    die("Application is not installed yet, please complete install wizard first.\n");
}

// Only for urls
// Don't remove this
$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
$_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);

Mage::app('admin')->setUseSessionInUrl(false);

umask(0);

$storeCode = 'default';

eLog("Outputting a list of all enabled shipping methods for store code: {$storeCode}.");

$methods = Mage::getSingleton('shipping/config')->getActiveCarriers(Mage::app()->getStore($storeCode));
$shipping = array();
foreach ($methods as $_ccode => $_carrier) {
    if ($_methods = $_carrier->getAllowedMethods())  {
        if (!$_title = Mage::getStoreConfig("carriers/$_ccode/title"))
            $_title = $_ccode;
        foreach ($_methods as $_mcode => $_method)   {
            $_code = $_ccode . '_' . $_mcode;
            $shipping[$_code] = array('title' => $_method,'carrier' => $_title);
        }
    }
}
echo "\n";
print_r($shipping);

function eLog($message)
{
    if (is_string($message)) {
        echo $message . "\n";
    }
    else {
        print_r($message);
    }
}