How I ended up solving this:
app/code/WSS/OrderHistory/registration.php
<?php \Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE, 'WSS_OrderHistory',
__DIR__
);
app/code/WSS/OrderHistory/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Block\Adminhtml\Order\View\Info">
<plugin name="customer_order_history" type="WSS\OrderHistory\Plugin\Block\Adminhtml\OrderHistory" sortOrder="15"/>
</type>
</config>
app/code/WSS/OrderHistory/etc/module.xml
<?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="WSS_OrderHistory" setup_version="0.0.1">
</module>
</config>
app/code/WSS/OrderHistory/Plugin/Block/Adminhtml/OrderHistory.php
<?php
namespace WSS\OrderHistory\Plugin\Block\Adminhtml;
class OrderHistory extends \Magento\Framework\View\Element\Template
{
protected $_orderCollectionFactory;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
array $data = []
)
{
$this->_orderCollectionFactory = $orderCollectionFactory;
parent::__construct($context, $data);
}
public function getOrderCollection($email)
{
$collection = $this->_orderCollectionFactory->create()
->addAttributeToSelect('*')
->addFieldToFilter('customer_email', $email)
->setOrder('entity_id','desc');
return $collection;
}
}
app/code/WSS/OrderHistory/view/adminhtml/layout/sales_order_view.xml
<?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">
<body>
<referenceBlock name="order_additional_info">
<block class="Magento\Backend\Block\Template" name="custom_block" template="WSS_OrderHistory::order/view/history.phtml" />
</referenceBlock>
</body>
</page>
app/code/WSS/OrderHistory/view/adminhtml/templates/order/view/history.phtml
<?php
$currentOrder = $block->getLayout()->createBlock('\Magento\Sales\Block\Adminhtml\Order\View\Info')->getOrder();
$historyBlock = $block->getLayout()->createBlock('WSS\OrderHistory\Plugin\Block\Adminhtml\OrderHistory');
$currentEmail = $currentOrder->getCustomerEmail();
$orderCollection = $historyBlock->getOrderCollection($currentEmail);
if ($orderCollection->getSize() >= 2) {
?>
<section class="admin__page-section">
<div class="admin__page-section-title">
<span class="title"><?php /* @escapeNotVerified */ echo __('Order History / ') ?>
<?php
if ($orderCollection->getSize() > 20) echo 'Last 20 Orders (';
echo $orderCollection->getSize() . ' Total';
if ($orderCollection->getSize() > 20) echo ')';
?></span>
</div>
<div class="admin__page-section-content">
<?php
echo '<div class="fieldset">';
echo '<dl>';
//orders
$orderCollection->getSelect()->limit(20);
foreach($orderCollection as $order){
$history_id = $order->getEntityId();
$orderHistoryDate = $order->getCreatedAt();
$items = $order->getItemsCollection();
echo '<dt>' . $orderHistoryDate . ' (Order#: <a href="' . $this->getUrl('sales/order/view', array('order_id' => $history_id)) . '">' . ltrim(ltrim($order->getIncrementId(),"1"),"0") . '</a>) [Status: <span>' . $order->getStatus() . '</span>]</dt>';
// items
foreach($items as $item):
echo '<dd>' . round($item->getQtyOrdered(), 0) . 'x - ' . $item->getName() . ' (Part#: <a href="' . $item->getProduct()->getProductUrl() . '" target="_blank">' . $item->getSku() . '</a>)</dd>';
endforeach;
}
?>
</div>
</section>
<?php
}
?>