How Can I Create Magento 2 Customer Programmatically

I am looking for a way to create a Magento 2 customer programmatically?

You will need to use customerFactory to create a Magento 2 customer programmatically.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$CustomerFactory = $objectManager->get('Magento\Customer\Model\CustomerFactory');
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');

$websiteId  = $storeManager->getWebsite()->getWebsiteId();
$customer   = $CustomerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->setEmail("demo@domain.com"); 
$customer->setFirstname("First Name");
$customer->setLastname("Last name");
$customer->setPassword("password");
$customer->save();
$customer->sendNewAccountEmail();
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments