I want to fetch and show which customer bought which product and from where on front end. The issue is i am unable to fetch the above details through order increment id/order id.
So how can i get customer details on checkout_onepage_success
page.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI want to fetch and show which customer bought which product and from where on front end. The issue is i am unable to fetch the above details through order increment id/order id.
So how can i get customer details on checkout_onepage_success
page.
Well i would suggest to use Automatic Dependency injection
but if you are using object manager then you can do it like this
<?php //NOT TESTED THOUGH
--------------------
//Get Object Manager Instance
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($IncrementId); //Use increment id here.
$order->getCustomerName(); // Check that class. There are lot of functions for getting customers data. Though first you should check if any API available. Because thats a better solution.
app\code\Magento\Sales
the first folder is API. Though you are good to go now. You can use the above code now i guess. But magento can change the core code anytime.
Apr 3, 2017 at 10:53
<?php
// logined customer
if ($order->getCustomerFirstname()) {
$customerName = $order->getCustomerName();
} else {
// guest customer
$billingAddress = $order->getBillingAddress();
$customerName = $billingAddress->getFirstname() . ' ' .
$billingAddress->getLastname();
}
echo $customerName;
?>