By default, when a user first checks out they are presented with the shipping address form because they have no shipping address. Once they complete an order, the address they used is being saved to their account.
I would like to disable the address being saved to their account so that the user presented with the address form every time they order.
Updated in response to Ramkishan's reply
MyModule\Observer\SalesOrderPlaceAfterObserver.php
<?php
namespace Company\Vendors\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class SalesOrderPlaceAfterObserver implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getOrder();
$customerAddressId = $order->getShippingAddress()->getCustomerAddressId();
// Inject Magento\Customer\Api\AddressRepositoryInterface in constructor and remove customer address.
$this->customerAddressRepository->deleteById($customerAddressId);
}
}
Company\MyModule\etc\events.xml
<?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="sales_order_place_after">
<observer name="sales_order_place_after" instance="Company\Vendors\Observer\SalesOrderPlaceAfterObserver" />
</event>
</config>
This is what I currently have and when I go to complete the order, i get the error just above the "Place Order" button after pressing it but it says nothing at all. No text appears, just the error icon and error colour background
This is my first time creating an observer, where have I gone wrong?
Update
I've just noticed that each time it failed, it was saving the address. As I pressed the button 4 times to try and see an error message, I now have the same address saved 4 times as different addresses to the same user.