In my custom module I've created model/carrier.php to add custom shipping method, one of my custom shipping method will show up if magento free shipping method is not active, is there a way to do this?


public function collectRates(RateRequest $request)
   $method = $this->_rateMethodFactory->create();
   if($free_shipping_method != 'Active'){ //???
      /* Use method name */
      $method->setMethodTitle('England is My City');

1 Answer 1


You need to add the following code in your custom shipping module (carrier.php).

 * @var \Magento\OfflineShipping\Model\Carrier\Freeshipping
protected $_freeshipping;

 public function __construct(
\Magento\OfflineShipping\Model\Carrier\Freeshipping $freeshipping
) {
        $this->_freeshipping = $freeshipping;

public function collectRates(RateRequest $request)
        if (!$this->getConfigFlag('active') || $this->_freeshipping->getConfigData('active')) {
            return false;
 /** @var \Magento\Shipping\Model\Rate\Result $result */
        $result = $this->_rateResultFactory->create();

        /** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
        $method = $this->_rateMethodFactory->create();



        $amount = $this->getShippingPrice();



        return $result;

Hope this answer will help you. let me know you have any further issue. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.