Disable Frontend Registration Magento 2

Basically we have to override the function \Magento\Customer\Model\Registration::isAllowed() to achieve this.

Follow the below steps to create an extension PHPCodez_Disableregistration for this task.

1) Declare a module.

<?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="PHPCodez_Disableregistration" setup_version="0.0.1" />
</config>

2) Register a module.

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

3) Create di.xml file and add the below content.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> 
<preference for="Magento\Customer\Model\Registration" type="PHPCodez\Disableregistration\Model\Overrides\Registration" /> 
</config>

4) Override Registration.php

<?php
namespace PHPCodez\Disableregistration\Model\Overrides;
class Registration extends \Magento\Customer\Model\Registration {

private $scopeConfig;
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig) {
$this->scopeConfig = $scopeConfig;
}

public function isAllowed() {
return false;
}
}

5) Issue the following commands.

$ php bin/magento indexer:reindex
$ php bin/magento setup:upgrade
$ php bin/magento setup:di:compile
$ php bin/magento setup:static-content:deploy -f
$ php bin/magento cache:flush
Share

2 thoughts on “Disable Frontend Registration Magento 2”

  1. magento website design …very handful of web-sites that transpire to be in depth below, from our point of view are undoubtedly well really worth checking out…

Leave a Reply

Your email address will not be published. Required fields are marked *