Since the invoice uses the billing adress object of the order you can't save changes in the billing address which should affect only the invoice.
But you can try to use a plugin after the method getBillingAddress()
in the invoice model (Magento\Sales\Model\Order\Invoice
) and overwrite the
name fields (prefix, firstname, lastname etc. depending on your configuration / used fields).
A method like this should work for the suggested approach (don't forget to add the plugin in your di.xml
) :
public function afterGetBillingAddress(\Magento\Sales\Model\Order\Invoice $subject, $result)
{
$customer = $subject->getOrder()->getCustomer();
if ($customer->getId()){
$result->setFirstname($customer->getFirstname());
$result->setLastname($customer->getLastname());
//... add other name fields like prefix, middlename, suffix if needed
}
return $result;
}