How can I save a custom Customer Attribute value programmatically?
I have tried below code but it didn't work.
protected $customer;
public function __construct(
\Magento\Customer\Model\Customer $customer
)
{
$this->customer = $customer;
}
...
...
$customerId = "1";
$customer = $this->customer->load($customerId);
$data = "customer attribute value";
$customerData = $customer->getDataModel();
$customerData->setCustomAttribute('customer_attribute_code',$data);
$customer->updateData($customerData);
$customer->save();
Is there any other method to save the customer attribute?
Best Answer
I have got the solution