I am using magento 2. And I need to disable one payment method 'cash on delivery' to specific cities(not for countries).I found so many solutions but those are not meant for magento 2, I think those are for older versions.Because I couldn't find those files(or methods in the specified location) in my code. Can anyone help me ?
Any help will be appreciated.
Magento – need to disable cash on delivery to particular cities(not country), using magento 2
cash-on-deliverycheckoutmagento2order-statepayment-methods
Best Answer
You need to create a new module and use a 'plugin' to add some logic to the
isAvailable
method ofMagento\OfflinePayments\Model\Cashondelivery
.Example plugin class:
And you'd have this in
{module_dir}/etc/di.xml
: