- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2021
03:05 AM
11-11-2021
03:05 AM
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
Labels:
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2021
03:46 AM
11-11-2021
03:46 AM
Re: Add and save custom field on order view page
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.
200+ Magento 2 Extensions for Enhanced Shopping Experience.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2021
05:07 AM
11-12-2021
05:07 AM
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.