---
title: "Magento 2 Disable Payment Method For Certain Customer Groups"
url: "https://dolphinwebsolution.com/disable-payment-method-for-certain-customer-groups-in-magento-2"
date: "2021-10-26T08:38:51+05:30"
modified: "2023-08-25T09:07:06+05:30"
author:
  name: "Jigar Patel"
categories:
  - "Magento"
word_count: 618
reading_time: "4 min read"
summary: "How to disable payment method for certain customer groups in Magento 2. you might often need to disable some payment methods for some customer groups to provide a particular payment method for VIP ..."
description: "How to disable payment method for certain customer groups in Magento 2. you might often need to disable some payment methods for some customer groups to prov..."
keywords: "Disable Payment Method For Certain customer Groups,Disable Payment Method in magento 2,Disable Payment Method For Certain customer Groups for magento, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to use slick carousel slider in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-use-slick-carousel-slider-in-magento-2"
  - title: "How to Add Custom Tab to Admin Sales Order View in Magento 2"
    url: "https://dolphinwebsolution.com/add-custom-tab-to-admin-sales-order-view-in-magento-2"
  - title: "How To Change Responsive Breakpoint and Viewport in Magento 2"
    url: "https://dolphinwebsolution.com/change-breakpoint-and-viewport-in-magento-2"
---

# Magento 2 Disable Payment Method For Certain Customer Groups

_Published: October 26, 2021_  
_Author: Jigar Patel_  

![](https://dolphinwebsolution.com/wp-content/uploads/2021/10/Magento-2-Disable-Payment-Method-For-Certain-Customer-Groups-1024x536.png)

How to disable payment method for certain customer groups in Magento 2. you might often need to disable some payment methods for some customer groups to provide a particular payment method for VIP customers. when such time arrives, you would want to do it the right way.

Magento 2 Default functionality Customer groups determine which discounts are available and the tax class that is associated with the group. The default customer groups are General, Not Logged In, and Wholesale.

Also Like this: [Payment Restrictions Extension for Magento 2](https://dolphinwebsolution.com/shop/payment-restrictions-for-magento.html)

#### Steps to Disable a Payment Method for Certain Customer Groups

How to disable a payment method for a customer group in Magento 2, you’ll first need to create a simple Module.

Here we are using **Dolphin** as Vendor name and **MyModule** as the name of a module. You can change this according to your Vendor and Module name.

#### Step 1: Create Registration
Create **registration.php** file in the **app/code/Dolphin/MyModule** folder with the following code.

```
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Dolphin_MyModule',
    __DIR__
);
```

#### Step 2: Create a module
Create a **module.xml** file in the **app/code/Dolphin/MyModule/etc** folder with the following code.

```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Dolphin_MyModule" setup_version="1.0.0"></module>
</config>
```

#### Step 3: Create Events/xml File
Create an **events.xml** file in the folder **app/code/Dolphin/MyModule/etc** and use event **payment\_method\_is\_active** which will be called Payment method active.

```
<?xml version="1.0"?>
<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="dolphin_payment_disable" instance="Dolphin\Mymodule\Observer\PaymentMethodDisable" />
    </event>
</config>
```

Here you declare an observer named **PaymentMethodDisable** that will handle the event **payment\_method\_is\_active** which Magento dispatches every time payment method is active.

Now we need to create an Observer as defined in the [**events.xml** file](https://developer.adobe.com/commerce/php/development/components/events-and-observers/)

Read this: [Get All Payment Methods in Magento 2](https://dolphinwebsolution.com/get-all-payment-methods-in-magento-2)

#### Step 4: Create Observer File
Now, we need to create the Observer **PaymentMethodDisable.php** file in the **app/code/Dolphin/MyModule/Observer** with the following code.

```
<?php
namespace Dolphin\MyModule\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class PaymentMethodDisable implements ObserverInterface
{
    /**
     * @var \Magento\Customer\Model\Session
     */
    protected $_customerSession;

    /**
     * @param \Magento\Customer\Model\Session $customerSession
     */
    public function __construct(
        \Magento\Customer\Model\Session $customerSession
    ) {
        $this->_customerSession = $customerSession;
    }

    public function execute(Observer $observer)
    {
        $payment_method_code = $observer->getEvent()->getMethodInstance()->getCode();
        if ($payment_method_code == 'payroll')
        {
            $result = $observer->getEvent()->getResult();
            if ($this->_customerSession->isLoggedIn())
            {
                $customerGroupId = $this->_customerSession->getCustomer()->getGroupId();
                if ($customerGroupId == 1)
                {
                    $result->setData('is_available', false);
                }
            }
        }
    }
}
```

**Session** will extend core class **`Magento\Framework\Session\SessionManager`** to handle the session.

Get the customer details- ***$this->\_customerSession->getCustomer()->getId();*** will give you current customer id, You can also get customer’s other details ***$customerData->getData()*.**

Now setup the module.To setup module first time, we execute below command:

```
[dt_highlight color="" text_color="" bg_color=""]php bin/magento s:up[/dt_highlight]
[dt_highlight color="" text_color="" bg_color=""]php bin/magento s:s:d -f[/dt_highlight]
[dt_highlight color="" text_color="" bg_color=""]php bin/magento c:c[/dt_highlight]
```

I hope this blog is easy to understand about how to disable payment method for certain customer groups in Magento 2.

if you are facing any issues during implementation, use the comment section below!

**Happy Coding!**


---

_View the original post at: [https://dolphinwebsolution.com/disable-payment-method-for-certain-customer-groups-in-magento-2](https://dolphinwebsolution.com/disable-payment-method-for-certain-customer-groups-in-magento-2)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 06:53:41 UTC_  
