My goal is to delete the default shipping address of all customer. The code looks something like this:

foreach ($customerCollection as $customer) {

        $shippingAddress = $customer->getDefaultShippingAddress();

        $output->writeln("<info>{$id} Has been deleted..</info>");    

I always get "Area code is not set" error. I already set the area on the constructor of the object. The weird part is this error only occurs when calling the delete method. The save() method works fine without any error. The command will work fine if I remove:


Anyone can enlightened what's happening here?


Can you try with below code

$bootstraps = Bootstrap::create(BP, $_SERVER);
$obj = $bootstraps->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
  • Should I add that in the constructor of the command object? – Eric Libay Sep 11 '17 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.