I have developed custom shipping module. Now I want to show error message on shipping module if anything wrong like city, state, phone number etc.

I follow this link to create shipping method: https://www.mageplaza.com/magento-2-create-shipping-method/

How do I achieve this?


Override checkAvailableShipCountries() at


Here you can get city, state, country etc from \Magento\Framework\DataObject $request

Use $this->_rateErrorFactory for display error

Final Code:

public function checkAvailableShipCountries(\Magento\Framework\DataObject $request)
    $allowedCity = "ahmedabad,surat,morbi";
    $allowedCity = explode(',', $allowedCity);

    if(in_array($request->getDestCity(), $allowedCity)) {
        return $this;
    } else {
        $error = $this->_rateErrorFactory->create();
        $errorMsg = $this->getConfigData('specificerrmsg');
                'Sorry, but we can\'t deliver to the destination city with this shipping module.'
        return $error;

    return $this;
  • Hi can please tell me how to override Override checkAvailableShipCountries() in custom module – Divya Sekar Dec 4 '19 at 6:10

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.