4

I am working on custom email template.

So I needed customer Billing and Shipping address in below file.

/vendor/magento/module-sales/view/frontend/templates/email/items.phtml

Can any 1 help me to get customer address of placed order.

3

You can add this piece of code in the file:

<?php /** @var $_order \Magento\Sales\Model\Order */ ?>
<?php $_order = $block->getOrder() ?>
<?php $billingAddress = $_order->getBillingAddress(); ?>
<?php $shippingAddress = $_order->getShippingAddress(); ?>

With $billingAddress now you can get address e.g:

<?php echo $billingAddress->getStreet() ?>
  • Can you tell me how to get the whole address? Not like getFirstName() or else. – Nitesh Mar 22 '17 at 11:56
  • How can I call formattedBillingAddress() function their as like email templates – Nitesh Mar 22 '17 at 12:09
  • Solved my problem by following : $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $formatedAddress = $objectManager->get('\Magento\Sales\Model\Order\Email\Sender\OrderSender');print_r($formatedAddress->getFormattedBillingAddress($_order)); print_r($formatedAddress->getFormattedShippingAddress($_order)); – Nitesh Mar 22 '17 at 12:40
3

Solved my problem by following edit in below file:

/vendor/magento/module-sales/view/frontend/templates/email/items.phtml

$_order = $block->getOrder()
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$formatedAddress = $objectManager->get('\Magento\Sales\Model\Order\Email\Sender‌​\OrderSender');
print‌​_r($formatedAddress-‌​>getFormattedBilling‌​Address($_order)); 
print_r($formatedAddress->getFormattedShippingAddress($_orde‌​r));
  • 5
    Using object manager directly is not recommended. – diazwatson Oct 27 '17 at 0:18
  • getFormattedShippingAddress is protected method you cannot access outside. – Lead Developer Jun 14 '18 at 12:49
  • 1
    You can directly create object for Renderer class. $formatedAddress = $objectManager->get('\Magento\Sales\Model\Order\Address\Renderer'); echo $formatedAddress->format($_order->getShippingAddress(), 'html') – Lead Developer Jun 14 '18 at 12:52
  • i am getting with html tag how to remove it – Sarvesh Tiwari Jun 22 '18 at 14:33

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.