I want to disable the possibility to register as a new customer on the frontend of my Magento 2 Community Edition store (new customers are being created through a different process).
I think I could remove the "Create an Account" link from the top menu and remove the "New Customers" block on the right of the Customer Login page, but I'm looking for a more tight blocking of this functionality. I assume you could still enter the example.com/customer/account/create/
URL manually and see the registration form.
Best Answer
Magento 2 has a system in place to facilitate disabling customer registration. The customer module includes a model of which it's the sole purpose to return a boolean
true
orfalse
to indicate if customer registration is allowed. The "Create an Account" link block, the "New Customers" block template (on the Customer Login page) and the Customer Account Create and CreatePost Controllers consult that model and based on it's return value they do or do not display their content.This model is
\Magento\Customer\Model\Registration
:At first, it seems a bit weird to have a whole class that just returns
true
, but this is in place to facilitate a single point where the Magento 2 Enterprise module WebsiteRestrictions can hook into to manipulate the returned boolean value based upon the Website Restrictions configuration you can set in the back end of an Enterprise shop.You can use that very same construction to disable customer registration on your own in your Magento 2 Community Edition, like the module pointed out in the comments (https://github.com/deved-it/magento2-disable-customer-registration) is also doing. Just create an after Plugin on the
isAllowed()
method:app/code/MyStore/Customer/Plugin/Customer/Model/RegistrationPlugin.php
:app/code/MyStore/Customer/etc/di.xml
:Of course you can also introduce a config setting to decide whether to return
true
orfalse
, just like was done in the linked module on GitHub.