cancel
Showing results for 
Search instead for 
Did you mean: 

Add and save custom field on order view page

Add and save custom field on order view page

Hello,

 

How can I add a new input field on order view page - something similar to the 'comments section'.

Purpose I need it is to save some code reference into it for some orders.

I need it for admin only, so this is NOT a checkout field, and I ant to be able to show it under sales grid columns as well, and further edit from sale view page.

 

Any idea appreciated!

Thanks

2 REPLIES 2

Re: Add and save custom field on order view page

@itmultimobd453 

Decide a section where you want to add a custom field
and edit it based on your requirement.
For example:
Add the below code in app\code\Vendor\Module\view\adminhtml\layout\sales_order_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <!--add custom block -->
        <referenceBlock name="order_additional_info">
            <block class="Vendor\Module\Block\Adminhtml\Order\View\View" name="custom_view" template="order/view/view.phtml"/>
        </referenceBlock>
    </body>
</page>
Add the below code in app\code\Vendor\Module\Block\Adminhtml\Order\View\View.php
<?php
namespace Vendor\Module\Block\Adminhtml\Order\View\;
class View extends \Magento\Backend\Block\Template
{
    public function myFunction()
    {
        //your code
        return "Customers' Instruction";
    }
}
Add the below code in 
app\code\Vendor\Module\view\adminhtml\templates\order\view\view.phtml
<div>
    <h1><?php echo $block->myFunction()?></h1>
    <h3>Thank you.</h3>
</div>
Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: Add and save custom field on order view page

Well, what I find most difficult is that i need it to be an editable field which should be saved from the order view page. Displaying it inside a block wherever it's not the biggest challenge.