4

Default Magento payment method "Bank Tranfer" does not allow using HTML tags in Instructions text.

How can I change that?

  • Can you please give graphical detail what you actually want in your question ? – Hassan Ali Shahzad Apr 5 at 12:02
3
+50

As I understood you want to add some HTML tags to Bank transfer Payment method.

By default Magento escapeHtml when rendering Instruction for COD and Bank transfer Payment.

We need to Create a small module which will override getInstructions function.

let's create a module Pawan_Instructions.

app/code/Pawan/Instructions/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Pawan_Instructions',
__DIR__
);

app/code/Pawan/Instructions/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="Pawan_Instructions" setup_version="1.0.0">
   </module>
</config>

app/code/Pawan/Instructions/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\OfflinePayments\Model\InstructionsConfigProvider" type="Pawan\Instructions\Model\Rewrite\InstructionsConfigProvider" />
</config>

app/code/Pawan/Instructions/Model/Rewrite/InstructionsConfigProvider.php

<?php

namespace Pawan\Instructions\Model\Rewrite;

class InstructionsConfigProvider extends \Magento\OfflinePayments\Model\InstructionsConfigProvider

{
    public function getInstructions($code)
    {
        if($code == 'banktransfer'){//check payment method is banktransfer
            return nl2br($this->methods[$code]->getInstructions());// removed escapeHtml function!
        }else{
            return nl2br($this->escaper->escapeHtml($this->methods[$code]->getInstructions()));
        }
    }

}

Final Result will be:

Admin enter image description here

Front **Admin**

Note: I have checked and allow html tag for only banktransfer code, if you want for both, you can skip If condition.

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.