0

I am overriding the checkout success page, Vendor/Theme/Magento_Checkout/templates/success.phtml and I want to let the user to know that a confirmation e-mail is send to his/her e-mail address.

Is there any way to show the e-mail address, that the user has filled in the checkout page? I have tried searching for methods like getEmail but could not find anything.

1

Overwrite Magento\Checkout\Block\Onepage\Success

Vendor/Module/etc/frontend/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">
    <preference for="Magento\Checkout\Block\Onepage\Success" type="Vendor\Module\Block\Onepage\Success" />
</config>

Vendor/Module/Block/Onepage/Success.php


namespace Vendor\Module\Block\Onepage;

class Success extends \Magento\Checkout\Block\Onepage\Success
{
    public function getEmail()
    {
        $order = $this->_checkoutSession->getLastRealOrder();
        return $order->getCustomerEmail();
    }
}

Now inside your success.phtml


<?php echo $block->getEmail(); ?>

Make sure your template is define inside checkout_onepage_success.xml following way:


<block class="Magento\Checkout\Block\Onepage\Success" name="checkout.success" template="Magento_Checkout::success.phtml" cacheable="false"/>

That means Magento_Checkout before success.phtml in template attribute.

Clear cache.

  • If I were to reproduce this in app/ (instead of vendor/), would this be done in app/code or could I achieve this in my child theme under app/design/<theme>/<child_theme>? – Craig Jul 13 '17 at 9:38
  • 'app/code/Vendor/Module' should be ok – Sohel Rana Jul 13 '17 at 9:40

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.