cancel
Showing results for 
Search instead for 
Did you mean: 

How to customize Thank you page in Magento 2?

How to customize Thank you page in Magento 2?

Hi everyone,

I have just realized that the thank you page in Magento 2 is nearly an empty page and I want it to be more informative and attractive.

Is there a way to create the thank you page in Magento 2 like a CMS page?

Thank you!

2 REPLIES

Re: How to customize Thank you page in Magento 2?

Hi @Eazy_188,

 

The success template is /vendor/magento/module-checkout/view/frontend/templates/success.phtml

 

You don't want to edit that page (because it will be updated when a new release in the future).
You should create a new theme or an override to the module to use your custom phtml file.

 

 

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: How to customize Thank you page in Magento 2?

You can customize your success page using create simple module.

 

First create layout handle file,

Lets assume i have keep Test/Thankyou page modulename.

layout xml file path,

app/code/Test/Thankyou/View/frontend/layout/checkout_onepage_success.xml

 

<?xml version="1.0"?>
<body>
    <referenceContainer name="content">
        <block class="Test\Thankyou\Block\Thankyou" name="order.details.success" template="Test_Thankyou::order/success.phtml" after="-">        	
        </block>
    </referenceContainer>
    <referenceBlock name="checkout.success" remove="true"/>
</body>

Now create Block file,

app/code/Test/Thankyou/Block/Thankyou.php

<?php
namespace Test\Thankyou\Block;

class Thankyou extends \Magento\Sales\Block\Order\Totals
{
    protected $checkoutSession;
    protected $customerSession;
    protected $_orderFactory;
    
    public function __construct(
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Registry $registry,
        array $data = []
    ) {
        parent::__construct($context, $registry, $data);
        $this->checkoutSession = $checkoutSession;
        $this->customerSession = $customerSession;
        $this->_orderFactory = $orderFactory;
    }

    public function getOrder()
    {
        return  $this->_order = $this->_orderFactory->create()->loadByIncrementId(
            $this->checkoutSession->getLastRealOrderId());
    }

    public function getCustomerId()
    {
        return $this->customerSession->getCustomer()->getId();
    }
}

Now Create success.phtml file at below location,

app/code/Test/Thankyou/View/frontend/templates/order/success.phtml

 

<?php 
$order = $block->getOrder();
?>
<div class="checkout-success">
<?php if($order->getIncrementId()):?>
    <?php if ($block->getCustomerId()) :?>
        <p><?php echo __('Your order number is: '.$order->getIncrementId().')' ?>
        </p>
        <?php  else :?>
            <p><?php echo __('Your order # is: <span>%1</span>.',$order->getIncrementId()) ?></p>
        <?php endif;?>
        <p><?php echo __('We\'ll email you an order confirmation with details and tracking info.') ?></p>
<?php endif;?>
</div>

This is Simple demo for override success.phtml file into your module.

You can add extra function in Block file and call inside template file based on your customization of thank you page.

 

if issue solved, Click Kudos/Accept as Solutions.

If Issue Solved, Click Kudos/Accept As solutions.