I want to get customer id after new customer register successfully in Magento 2.2.2. In app/code/vendor/module/etc/frontend/events.xml-> I added this code
<?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="customer_register_success">
<observer name="update_customer_referal_code" instance="vendor\module\Observer\UpdateCustomerMeta" />
</event>
</config>
and in app/code/vendor/module/Observer/UpdateCustomerMeta.php -> I have added this
<?php
namespace vendor\module\Observer;
use Magento\Framework\Event\ObserverInterface;
class UpdateCustomerMeta implements ObserverInterface
{
protected $_customerRepositoryInterface;
public function __construct(
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface
) {
$this->_customerRepositoryInterface = $customerRepositoryInterface;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$customer = $observer->getEvent()->getCustomer();
print_r($customer->getId());
echo "if this string shows it means observer works";
exit();
}
}
but when I register a user it directly goes to customer panel after registering anyone please tell what mistake I am making.