I am using Magento 2.1 . I want to display purchase order number in customer dashboard.

enter image description here

  • did you figure out from which file its calling? Jan 7, 2019 at 21:53

1 Answer 1


You need to override recent.phtml template files in Magento_Sales module.
To fetch the purchase order number in the recent.phtml you can use the following code


You can try following code and modify it according to your requirement.


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Anshu_Custom" setup_version="1.0.0">
            <module name="Magento_Sales"/>



use Magento\Framework\Component\ComponentRegistrar;



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceContainer name="content">
            <block class="Magento\Sales\Block\Order\Recent" name="customer_account_dashboard_top" template="Anshu_Custom::recent.phtml"/>


<div class="block block-dashboard-orders">
    $_orders = $block->getOrders();
    $count = count($_orders);
    <div class="block-title order">
        <strong><?= /* @escapeNotVerified */ __('Recent Orders') ?></strong>
        <?php if ($count > 0): ?>
            <a class="action view" href="<?= /* @escapeNotVerified */ $block->getUrl('sales/order/history') ?>">
                <span><?= /* @escapeNotVerified */ __('View All') ?></span>
        <?php endif; ?>
    <div class="block-content">
        <?= $block->getChildHtml() ?>
        <?php if ($count > 0): ?>
            <div class="table-wrapper orders-recent">
                <table class="data table table-order-items recent" id="my-orders-table">
                    <caption class="table-caption"><?= /* @escapeNotVerified */ __('Recent Orders') ?></caption>
                        <th scope="col" class="col id"><?= /* @escapeNotVerified */ __('Order #') ?></th>
                        <th scope="col" class="col po"><?= /* @escapeNotVerified */ __('Purchase Order #') ?></th>
                        <th scope="col" class="col date"><?= /* @escapeNotVerified */ __('Date') ?></th>
                        <th scope="col" class="col shipping"><?= /* @escapeNotVerified */ __('Ship To') ?></th>
                        <th scope="col" class="col total"><?= /* @escapeNotVerified */ __('Order Total') ?></th>
                        <th scope="col" class="col status"><?= /* @escapeNotVerified */ __('Status') ?></th>
                        <th scope="col" class="col actions"><?= /* @escapeNotVerified */ __('Action') ?></th>
                    <?php foreach ($_orders as $_order): ?>
                            <td data-th="<?= $block->escapeHtml(__('Order #')) ?>" class="col id"><?= /* @escapeNotVerified */ $_order->getRealOrderId() ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Purchase Order #')) ?>" class="col purchaseorder"><?= /* @escapeNotVerified */ $_order->getPayment()->getPoNumber() ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date"><?= /* @escapeNotVerified */ $block->formatDate($_order->getCreatedAt()) ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Ship To')) ?>" class="col shipping"><?= $_order->getShippingAddress() ? $block->escapeHtml($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Order Total')) ?>" class="col total"><?= /* @escapeNotVerified */ $_order->formatPrice($_order->getGrandTotal()) ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Status')) ?>" class="col status"><?= /* @escapeNotVerified */ $_order->getStatusLabel() ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Actions')) ?>" class="col actions">
                                <a href="<?= /* @escapeNotVerified */ $block->getViewUrl($_order) ?>" class="action view">
                                    <span><?= /* @escapeNotVerified */ __('View Order') ?></span>
                                <?php if ($this->helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?>
                                    <a href="#" data-post='<?php /* @escapeNotVerified */ echo
                                    ?>' class="action order">
                                        <span><?= /* @escapeNotVerified */ __('Reorder') ?></span>
                                <?php endif ?>
                    <?php endforeach; ?>
        <?php else: ?>
            <div class="message info empty"><span><?= /* @escapeNotVerified */ __('You have placed no orders.') ?></span></div>
        <?php endif; ?>
  • Thanks for you response. without overriding the recent.phtml template, can we change only recent.phtml file
    – kiran
    Jan 8, 2019 at 13:52
  • @kiran if you don't want to override using module than you override it in your custom theme. But anyway you have to override it as doing change directly in core file is a bad coding practice. Jan 8, 2019 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.