0

If the payment method is bank transfer, I need to show a custom message on success page of Magento 2.

I'm going to say

"don't forget: we will ship to you after your payment received to our bank account; here are our bank details; and you have 2 days left to make your payment"

etc..

I found the solution as like below (with editing success.phtml), but you know, I don't want to edit core files.

<?php if ($this->getOrderId()):?>
<div class="bank_detail">
<?php $orderId = $this->getOrderId(); ?>
<?php $order = Mage::getModel("sales/order")->loadByIncrementId($orderId); //load order by increment id?>
<?php $paymentCode = $order->getPayment()->getMethod(); ?>

   <?php if ($paymentCode=='banktransfer') { 
       echo "whatever you want!";
   } //you can also check for other payment method?>

Could someone help me to do this with the module?

5
  • You can try by 'order.success.additional.info'
    – kunj
    May 16, 2018 at 13:10
  • it is possible by creating one simple module and call you custom phtml file on the success page. May 16, 2018 at 13:11
  • @erererer please check my answer and let me know It will help you. May 16, 2018 at 13:20
  • No need to create any custom module. You can simply create a widget from the admin panel and call it on the checkout success page. May 16, 2018 at 13:23
  • could someone help me to modify success.phtml or create custom_info.phtml? i need to say 'if payment method=banktransfer, echo xxxx' etc
    – erererer
    May 16, 2018 at 20:14

1 Answer 1

0

If you don't want to create the new module, you can do it in your theme as well. Follow below steps:

Create checkout_onepage_success.xml in your theme.

For example:

app/design/frontend/Package/Theme/Magento_Checkout/layout/checkout_onepage_success.xml.

The content of file is:

<?xml version="1.0"?>
<body>
    <referenceContainer name="order.success.additional.info">
        <block class="Magento\Checkout\Block\Onepage\Success"
               name="custom_info.order.success"
               template="Magento_Checkout::order/success/custom_info.phtml"
               after="-">
        </block>
    </referenceContainer>
</body>

Then you need to create the template file:

app/design/frontend/Package/Theme/Magento_Checkout/templates/order/success/custom_info.phtml.

You can add your conditional code to this file.

For example:

My bank information is xyz

Run:

php bin/magento cache:flush

4
  • thank you so so much for your kind answer.. but, could you please show me a way with a creating new module? (i need to write bank details, IF payment method is bank transfer)
    – erererer
    May 16, 2018 at 13:29
  • you can create a system configuration field and add your data to this field and call it on 'custom_info.phtml' it will done :) May 16, 2018 at 13:33
  • if any answer solves your concern then there is green right tick mark , hit that tickmark for right ansewer that will help future readers. May 16, 2018 at 13:33
  • May i also please you to give an custom_info.phtml example? if paymentmethod=bank transfer) { echo 'bank details: xxxx'; } etc..
    – erererer
    May 16, 2018 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.