How to disable the Cash on Delivery payment method in backend and frontend How to disable payment method COD in Back and front end in magento2 ProgrammaticallyProgrammatically?
Here the code I'm using:
etc/di.xml
<type name="Magento\OfflinePayments\Model\Cashondelivery">
<plugin name="cashondeliveryplugin" type="Xxx\Yyy\Plugin\Model\Cashondelivery" sortOrder="10" disabled="false" />
</type>
Plugin:
public function aroundIsAvailable(
\Magento\OfflinePayments\Model\Cashondelivery $subject,
callable $proceed,
$quote = null
) {
$result = $proceed($quote);
$codAvailability = $this->_pincodeModel->isCODAvailable($quote->getShippingAddress()->getPostcode()) ? "yes" : "no";
if ($codAvailability == 'no') {
return false;
}
return $result;
}
The actual problem is: the quote is missed when plugin called from the frontend (checkout page).