Magento 2 Shipping Methods

🚚 Magento 2 Shipping Methods – Configure, Add, and Customize

Shipping methods in Magento 2 allow you to define how products are delivered to your customers. Magento comes with several built-in methods like Flat Rate, Free Shipping, Table Rates, and integrations like UPS, FedEx, and DHL.

⚙️ Configure Built-in Shipping Methods

To enable or configure existing shipping methods:

  1. Go to Stores > Configuration > Sales > Shipping Methods
  2. Click on the shipping method (e.g., Flat Rate)
  3. Enable it and fill out the required details

🔧 Example: Enable Free Shipping Programmatically

You can enable Free Shipping using Magento’s config writer:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$configWriter = $objectManager->get(\Magento\Framework\App\Config\Storage\WriterInterface::class);

$configWriter->save(
    'carriers/freeshipping/active',
    1,
    \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
    0
);

Try It Now

➕ Create a Custom Shipping Method

Creating your own shipping method involves:

  • Creating a new module
  • Creating a model extending \Magento\Shipping\Model\Carrier\AbstractCarrierOnline or AbstractCarrier
  • Declaring it in etc/config.xml and etc/di.xml

🔧 Example: Basic Custom Shipping Model

namespace Vendor\Shipping\Model\Carrier;

use Magento\Quote\Model\Quote\Address\RateRequest;
use Magento\Shipping\Model\Carrier\AbstractCarrier;
use Magento\Shipping\Model\Carrier\CarrierInterface;

class CustomShipping extends AbstractCarrier implements CarrierInterface
{
    protected $_code = 'customshipping';

    public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }

        $result = $this->_rateResultFactory->create();
        $method = $this->_rateMethodFactory->create();

        $method->setCarrier($this->_code);
        $method->setCarrierTitle($this->getConfigData('title'));
        $method->setMethod('standard');
        $method->setMethodTitle('Standard Shipping');
        $method->setPrice(10);
        $method->setCost(0);

        $result->append($method);
        return $result;
    }

    public function getAllowedMethods()
    {
        return [$this->_code => $this->getConfigData('name')];
    }
}

Try It Now

📦 Popular Third-Party Shipping Integrations

Magento supports third-party carriers like:

  • ShipStation
  • ShipperHQ
  • Easyship

These extensions provide more flexibility like live rates, delivery estimates, and carrier rule-based shipping.

✅ Summary

  • Magento offers flexible shipping out-of-the-box
  • You can create fully custom methods using modules
  • Programmatic changes are easy with config writers
  • Third-party extensions add real-time rates & automation

With the right shipping configuration, you can reduce cart abandonment, offer multiple options, and make logistics a breeze. Time to ship success! 📦✨