Override checkAvailableShipCountries()
at
app/code/Vendor/Module/Model/Carrier/Myshipping.php
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();
$error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title'));
$errorMsg = $this->getConfigData('specificerrmsg');
$error->setErrorMessage(__(
'Sorry, but we can\'t deliver to the destination city with this shipping module.'
)
);
return $error;
}
return $this;
}