Magento2 Checkout – Change Customer Salutation on Success Page

checkoutmagento2order-success-pagetemplate

How can I get customer information on success page (template I think is "success.phtml"). I want to set it to something link "Dear Mr. Hans Mustermann …"

in success.phtml I found this code

$block->getOrderId()

I have tried $block->getCustomerName() or $block->getCustomerGender() but it does not work.

Best Answer

You can use below code to get ordered customer details.

$lid = $block->getOrderId();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($lid);
$billingAddress = $order->getBillingAddress();
echo $billingAddress->getFirstname().' '.$billingAddress->getLastname();

Hope this will be helpful.

Related Topic