Skip to content

How to show custom block on success page programmatically

I’m using Magento 2.4.7-p1 and I’m trying to show programmatically a customer block on the success page from my module but without success.

The module seems correctly enabled and registered but the custom block is not shown. No other info in the log files. I also run magento setup:upgrade, magento cache:flush, etc. Products are downloadables.

Here’s what I done:

Vendor/Module/registration.php

<?php

use MagentoFrameworkComponentComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__);

Vendor/Module/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="Vendor_Module" setup_version="1.0.0">
    </module>
</config>

Vendor/Module/view/frontend/layout/checkout_onepage_success.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>
        <referenceContainer name="order.success.additional.info">
            <block class="MagentoCheckoutBlockOnepageSuccess"
                    name="test2.order.success"
                    template="Vendor_Module::order/success.phtml"
                    cacheable="false"
                    after="-">
            </block>
        </referenceContainer>
    </body>
</page>

Vendor/Module/view/frontend/templates/order/success.phtml

<?php
echo "My custom content!";