Skip to main content
added 822 characters in body; edited tags
Source Link
Siarhey Uchukhlebau
  • 16.2k
  • 11
  • 55
  • 88

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).

How to disable payment method COD in Back and front end in magento2 Programmatically?

How to disable the Cash on Delivery payment method in backend and frontend Programmatically?

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).

added 17 characters in body
Source Link
Mahi M
  • 2.5k
  • 2
  • 37
  • 84

How to disable payment method COD in Back and front end in magento2 Programmatically?

How to disable payment method COD in Back and front end in magento2?

How to disable payment method COD in Back and front end in magento2 Programmatically?

Source Link
Mahi M
  • 2.5k
  • 2
  • 37
  • 84

Payment method in magento2?

How to disable payment method COD in Back and front end in magento2?