For you are requirement, you need to create a plugin for class
Magento\Checkout\Block\Onepage\Success
In this, you need to pass order object to template file
And using after method of prepareBlockData(), you can do that.
Plugin
<?php
namespace My\Module\Plugin;
class AppendValueAtSuccesspage
{
public function __construct(
\Magento\Sales\Model\OrderFactory $orderFactory
) {
$this->orderFactory = $orderFactory;
}
public function afterPrepareBlockData(\Magento\Checkout\Block\Onepage\Success $subject, $result)
{
$orderIncrementId = $result->getOrderId();
$order = $this->orderFactory->create()->loadByIncrementId($orderIncrementId);
$result->setOrderObject($order);
return $result;
}
}
?>
di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Block\Onepage\Success">
<plugin name="addorderToTemplate" type="My\Module\Plugin\AppendValueAtSuccesspage" />
</type>
</config>
success.phtml
you can get Order object from getOrderObject()
<?php $_order = $block->getOrderObject() ?>
<?php echo __(' %1', $block->escapeHtml($_order->getCustomerFirstname() ? $_order->getCustomerName() : $_order->getBillingAddress()->getName())) ?>