3

I need to add custom block after order comment section in admin order create form using version(magento2.2.5)

5

First,you have to create a custom module.On your custom

Create sales_order_create_index.xml at app/code/{VendorName}/{ModuleName}/view/adminhtml/layout/ and add below code:

<?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="content">
            <block class="{YourBlockClass}" template="{yourTemplate}" after="comment" name="{nameOnLayout}"/>
        </referenceContainer>
    </body>
</page>

Update

You can achieve this via plugin

Create plugin on class Magento\Sales\Block\Adminhtml\Order\Create\Comment

and add you custom block output with this block

namespace Magento\Sales\Block\Adminhtml\Order\Create;

class CommentPlugin
{
    public function afterToHtml(\Magento\Sales\Block\Adminhtml\Order\Create\Comment $subject, $html)
    {
        $newBlockHtml = $subject->getLayout()->createBlock('Full\Block\Class\Name\Here')->setTemplate({yourTemplate})->toHtml();

    reeturn $html.$newBlockHtml;
    }
}
  • It displayed after the order submit button and also select customer section....But i need this ..after order comment text box and before order submit button. – Mano M Aug 1 '18 at 5:23
2

Taking ref from @AmitBera

Create etc/adminhtml/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">
    <type name="Magento\Sales\Block\Adminhtml\Order\Create\Comment">
        <plugin name="after_order_create_comment" type="NameSpace\ModuleName\Plugin\Sales\Block\Adminhtml\Order\Create\CommentPlugin" sortOrder="10"/>
    </type>
</config>

And your NameSpace\ModuleName\Plugin\Sales\Block\Adminhtml\Order\Create\CommentPlugin.php

<?php namespace DigitalCinema\Pos\Plugin\Sales\Block\Adminhtml\Order\Create;

class CommentPlugin
{
    public function afterToHtml(\Magento\Sales\Block\Adminhtml\Order\Create\Comment $subject, $html)
    {
        $newBlockHtml = $subject->getLayout()->createBlock('\Magento\Framework\View\Element\Template')->setTemplate('NameSpace_ModuleName::path/to/template.phtml')->toHtml();

        return $html.$newBlockHtml;
    }
}

You should change \Magento\Framework\View\Element\Template to your own block class.

Can confirm, it is working in my M2 instance.

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.