0

Is it possible to show disabled payment methods only in admin while creating order from Admin / Sales / Orders and not in front end.

1

2 Answers 2

0

You can create a plugin to control which method you will show in the frontend, creating a plugin for:

Magento\Payment\Model\MethodList

Then you check the method by code and disabled which you want:

public function afterGetAvailableMethods(\Magento\Payment\Model\MethodList $subject, $result)
{
    foreach ($result as $key=>$_result) {
        if ($_result->getCode() == "cashondelivery") {
            unset($result[$key]);
        }
    }
    return $result;
}

In this way, you can show the payment method in the admin area only and disable it in the frontend area.

0

Try

Create a global event for payment_method_is_active

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="payment_method_is_active">
        <observer name="mp_payment_restrictions" instance="MagePal\PaymentRestrictions\Observer\PaymentMethodActiveObserver" />
    </event>
</config>

In MagePal/PaymentRestrictions/Observer/PaymentMethodActiveObserver.php

class PaymentMethodActiveObserver implements ObserverInterface
{
    public function __construct(
        ..
    ) {
        ...
    }

    public function execute(Observer $observer)
    {  

        $methodInstance = $observer->getMethodInstance();
        $paymentCode = $methodInstance->getCode();  

        //todo: check if processing from backend or frontend 
        if ($result->getIsAvailable() && $paymentCode !== 'xyz') {
           $result->setIsAvailable(false);
        }
    }
}
2
  • Thank you for your reply. This is not working. Still am getting only "Purchased Order" method nothing else. Commented Jul 7, 2022 at 16:17
  • Can you add some code to your original post? Commented Jul 7, 2022 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.