Disable customer in Magento

Disable customer in Magento

July 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Disable customer in Magento

Disabling Customer Accounts in Magento: A Step-by-Step Guide

In this post, we’ll explore how to implement user account disabling functionality in your Magento store. As a senior developer at LaravelCompany, I’ve worked extensively with Magento and understand the importance of efficiently managing customer accounts.

Why Disable Customer Accounts?

Disabling customer accounts instead of deleting them allows you to preserve critical data while preventing unauthorized access. This is particularly useful when dealing with inactive or potentially malicious users who might otherwise clog your system or expose sensitive information.

Step 1: Create a New Attribute for Account Status

First, we need to create an additional attribute to store the account status (enabled/disabled). Head over to the Magento Admin Panel and navigate to Stores > Attributes > Customer. Click on Add New Attribute.

Configure your new attribute as follows:

  • Attribute Code: account_status
  • Scope: Global
  • Input Type for Store Owner: Drop-down
  • Values: Set to “Enabled”, “Disabled”
  • Default Value: “Enabled”
  • Visible on Website: Checked
  • Used in Form Display: Checked

Click Save Attribute.

Step 2: Update Customer Registration and Login Processes

Next, we need to modify the customer registration and login processes to include this new status field.

Registration Process

In your custom theme’s registration form template (e.g., app/design/frontend/{vendor}/{theme}/template/customer/form/register.phtml), add a hidden input for the account_status attribute:

<input type="hidden" name="account_status" value="Enabled">

Login Process

For login functionality, you can use Magento’s built-in login form templates without modifications. However, ensure your customer registration is handling the new account_status field correctly.

Step 3: Create an Admin Interface for Account Disabling

To provide administrators with a way to disable accounts, create a custom grid and action in the admin panel.

Creating a Custom Grid

Create a new file named app/code/{Vendor}/{Module}/view/adminhtml/ui_component/customer_grid.xml and add the following content:

<grid name="customer_grid">
    <columns name="customer_columns">
        <column name="account_status">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">select</item>
                    <item name="options" xsi:type="array">
                        <item name="Enabled" xsi:type="string" translate="true">Enabled</item>
                        <item name="Disabled" xsi:type="string" translate="true">Disabled</item>
                    </item>
                </item>
            </argument>
        </column>
    </columns>
</grid>

This code adds a new column for the account_status attribute to your customer grid.

Creating an Action for Disabling Accounts

Create a new file named app/code/{Vendor}/{Module}/Controller/Adminhtml/Customer/Disable.php:

namespace {Vendor}\{Module}\Controller\Adminhtml\Customer;

use Magento\Framework\Controller\ResultFactory;
use Magento\Customer\Model\CustomerFactory;

class Disable extends \Magento\Backend\App\Action
{
    protected $customerFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        CustomerFactory $customerFactory
    ) {
        $this->customerFactory = $customerFactory;
        parent::__construct($context);
    }

    public function execute()
    {
        $customerId = (int)$this->getRequest()->getParam('id');
        $customer = $this->customerFactory->create();
        $customer->load($customerId);

        if ($customer->getEntityId()) {
            $customer->setAccountStatus('Disabled')->save();
        }

        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        return $resultRedirect->setPath('*/*/');
    }
}

This file creates an admin controller action that loads the selected customer and sets their account_status to “Disabled”.

Step 4: Notifying Disabled Customers

To send a notification email, create a new Observer in your module:

namespace {Vendor}\{Module}\Observer;

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

class CustomerDisableEmail implements ObserverInterface
{
    // Implement the constructor and execute method as needed for your email configuration

    public function execute(Observer $observer)
    {
        // Logic to send an email notification to the disabled customer using their contact details
    }
}

Step 5: Testing Your Solution

After implementing these steps, you should be able to disable customer accounts in your Magento store. Test by creating a new account, then enabling and disabling it through the admin panel.

Remember that this is a basic implementation. For production use, ensure you handle edge cases properly, such as when a customer tries to log in with a disabled account.

For more advanced customizations and integrations, feel free to reach out to our team at LaravelCompany. Our expert developers are always happy to help you optimize your e-commerce platform.

Themes Admin Configuration Customers

Our network