3

I want to add custom success page by overriding it's phtml.

Can anyone guide me how can I do this?

5

Copy This File :-

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

And Paste In Your Theme :-

app/design/frontend/your/theme/Magento_Checkout/view/frontend/templates/

After This You Can Change Success Page As Per Your Requirement

  • Magento_Catalog or Magento_Checkout ? – Muhammad Anas Apr 8 at 11:38
  • Magento_Checkout – Rk Rathod Apr 8 at 11:38
  • 1
    Thanks Ronak Rathod, will try this one – Muhammad Anas Apr 8 at 11:38
  • most welcome... – Rk Rathod Apr 8 at 11:39
3

You can do it by overriding or extending checkout_onepage_success.xml with your custom module. Follow these steps:

  1. Create your Success.php Block file in vendor\module\Block\OnePage
<?php
namespace vendor\module\Block\OnePage;
class Success extends \Magento\Framework\View\Element\Template
{
    public function getCustomSuccess()
    {
        return 'Your custom contents.';
    }
} 
  1. Create checkout_onepage_success.xml layout file in vendor\module\view\frontend\layout
<?xml version="1.0"?>
<body>
    <referenceContainer name="order.success.additional.info">
        <block class="vendor\module\Block\OnePage\Success"
               name="custom.order.success"
               template="Vendor_Module::order/success.phtml"
               after="-">
        </block>
    </referenceContainer>
</body>  
  1. Lastly, create phtml template file in vendor\module\view\frontend\templates\order\success.phtml
<?php /* @var $block \vendor\module\Block\OnePage\Success */?>
<?php echo __('This is a custom content.'); ?>
<?php echo $block->getCustomSuccess(); ?>  

After done with the above steps, run the upgrade command and redeploy static view files.

3

you need to copy

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

into

app/design/frotend/<your package name/<your theme name>/Magento_Checkout/templates/success.phtml

then do cache flush using below command

php bin/mageno c:f

Then check it

3

Go to magento core file given path and Copy This File

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

And Paste In below path

app/design/frontend/theme_package/theme_name/Magento_Checkout/view/frontend/templates/

Run below command

php bin/magento c:c

php bin/magento c:f


You can also do it in module way

app/code/Namespace/Modulename/view/frontend/layout/checkout_onepage_success.xml

<?xml version="1.0"?>
<body>
<referenceContainer name="order.success.additional.info">
    <block class="Namespace\Modulename\Block\Success"
           name="test.order.success"
           template="Namespace_Modulename::order/success.phtml"
           after="-">
    </block>
</referenceContainer>
</body>

app/code/Namespace/Modulename/view/frontend/templates/order/success.phtml

<?php echo __('Custom template file content.'); ?>
<?php echo $block->getSomething(); ?>

I hope it helps

  • Thanks for the answer. +1 – Muhammad Anas Apr 8 at 12:07
  • you are welcome. +1 for your appreciation :) – Chirag Patel Apr 8 at 12:17

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.