We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Create the events.xml file in your custom module and add the below code.
    <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="cust_payment_disable" instance="VendorModuleObserverPaymentDisable" />
        </event>
    </config>
    Create observer PaymentDisable.php file in your customer module and add below code.
    <?php
    namespace VendorModuleObserver;
    use MagentoFrameworkEventObserver;
    use MagentoFrameworkEventObserverInterface;
    
    class PaymentDisable implements ObserverInterface {
        protected $_customerSession;
        public function __construct(
           MagentoCustomerModelSession $customerSession,
           MagentoCustomerModelGroupRegistry $groupRegistry
        ) {
           $this->_customerSession = $customerSession;
           $this->groupRegistry = $groupRegistry;
        }
        public function execute(Observer $observer) {
           $payment_method_code = $observer->getEvent()->getMethodInstance()->getCode();
           if ($payment_method_code == 'purchaseorder') {
               $result = $observer->getEvent()->getResult();
                if ($this->_customerSession->isLoggedIn()) {
                    $customer = $this->_customerSession->getCustomer();
                    $customerGroup = $customer->getGroupId();
                    if($customerGroup == 4){
                        $result->setData('is_available', false);
                    }
                }
            }
        }
    }

     

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote