Hello Magento Friends,
In the current article, we are going to focus on Magento 2: How to Add Custom Text after Billing Address and Shipping Address in Admin Order View Page.
With Magento 2 you can customize any part of the store. Admin order view page is where the store admin manages all orders after the order is placed by customers. Admin sales order view page in Magento 2 can be customized for better order processing.
You can Add Custom Block After Shipping and Billing Address in Admin Sales order view page in Magento 2. Same way today we will learn How to Add Custom Text after Billing Address and Shipping Address in the Admin Order View Page in Magento 2.
Contents
Steps to Add Custom Text after Billing Address and Shipping Address in Admin Order View Page in Magento 2:
Step 1: First, we need to create a “sales_order_view.xml“ file inside our extension at the following path
app\code\Vendor\Extension\view\adminhtml\layout\
Then add the below code
1 2 3 4 5 6 7 8 9 10 11 |
<?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> <referenceBlock name="order_info"> <action method="setTemplate"> <argument name="template" translate="true" xsi:type="string">Vendor_Extension::order/info.phtml</argument> </action> </referenceBlock> </body> </page> |
Step 2: After that, we need to create an “info.phtml” file inside our extension at the following path
app\code\Vendor\Extension\view\adminhtml\templates\order\
Now add the code as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ /** * @var \Magento\Sales\Block\Adminhtml\Order\View\Info $block */ $order = $block->getOrder(); $baseCurrencyCode = (string)$order->getBaseCurrencyCode(); $globalCurrencyCode = (string)$order->getGlobalCurrencyCode(); $orderCurrencyCode = (string)$order->getOrderCurrencyCode(); $orderAdminDate = $block->formatDate( $block->getOrderAdminDate($order->getCreatedAt()), \IntlDateFormatter::MEDIUM, true ); $orderStoreDate = $block->formatDate( $order->getCreatedAt(), \IntlDateFormatter::MEDIUM, true, $block->getTimezoneForStore($order->getStore()) ); $customerUrl = $block->getCustomerViewUrl(); $allowedAddressHtmlTags = ['b', 'br', 'em', 'i', 'li', 'ol', 'p', 'strong', 'sub', 'sup', 'ul']; ?> <section class="admin__page-section order-view-account-information"> <div class="admin__page-section-title"> <span class="title"><?= $block->escapeHtml(__('Order & Account Information')) ?></span> </div> <div class="admin__page-section-content"> <div class="admin__page-section-item order-information"> <?php /* Order Information */ ?> <?php $confirmationEmailStatusMessage = $order->getEmailSent() ? __('The order confirmation email was sent') : __('The order confirmation email is not sent'); ?> <div class="admin__page-section-item-title"> <span class="title"> <?php if ($block->getNoUseOrderLink()) : ?> <?= $block->escapeHtml(__('Order # %1', $order->getRealOrderId())) ?> (<span><?= $block->escapeHtml($confirmationEmailStatusMessage) ?></span>) <?php else : ?> <a href="<?= $block->escapeUrl($block->getViewUrl($order->getId())) ?>"><?= $block->escapeHtml(__('Order # %1', $order->getRealOrderId())) ?></a> <span>(<?= $block->escapeHtml($confirmationEmailStatusMessage) ?>)</span> <?php endif; ?> </span> </div> <div class="admin__page-section-item-content"> <table class="admin__table-secondary order-information-table"> <tr> <th><?= $block->escapeHtml(__('Order Date')) ?></th> <td><?= $block->escapeHtml($orderAdminDate) ?></td> </tr> <?php if ($orderAdminDate != $orderStoreDate) : ?> <tr> <th><?= $block->escapeHtml(__('Order Date (%1)', $block->getTimezoneForStore($order->getStore()))) ?></th> <td><?= $block->escapeHtml($orderStoreDate) ?></td> </tr> <?php endif;?> <tr> <th><?= $block->escapeHtml(__('Order Status')) ?></th> <td><span id="order_status"><?= $block->escapeHtml($order->getStatusLabel()) ?></span></td> </tr> <?= $block->getChildHtml() ?> <?php if ($block->isSingleStoreMode() == false) : ?> <tr> <th><?= $block->escapeHtml(__('Purchased From')) ?></th> <td><?= $block->escapeHtml($block->getOrderStoreName(), ['br']) ?></td> </tr> <?php endif; ?> <?php if ($order->getRelationChildId()) : ?> <tr> <th><?= $block->escapeHtml(__('Link to the New Order')) ?></th> <td> <a href="<?= $block->escapeUrl($block->getViewUrl($order->getRelationChildId())) ?>"> <?= $block->escapeHtml($order->getRelationChildRealId()) ?> </a> </td> </tr> <?php endif; ?> <?php if ($order->getRelationParentId()) : ?> <tr> <th><?= $block->escapeHtml(__('Link to the Previous Order')) ?></th> <td> <a href="<?= $block->escapeUrl($block->getViewUrl($order->getRelationParentId())) ?>"> <?= $block->escapeHtml($order->getRelationParentRealId()) ?> </a> </td> </tr> <?php endif; ?> <?php if ($order->getRemoteIp() && $block->shouldDisplayCustomerIp()) : ?> <tr> <th><?= $block->escapeHtml(__('Placed from IP')) ?></th> <td><?= $block->escapeHtml($order->getRemoteIp()); ?><?= $order->getXForwardedFor() ? ' (' . $block->escapeHtml($order->getXForwardedFor()) . ')' : ''; ?></td> </tr> <?php endif; ?> <?php if ($globalCurrencyCode !== $baseCurrencyCode) : ?> <tr> <th><?= $block->escapeHtml(__('%1 / %2 rate:', $globalCurrencyCode, $baseCurrencyCode)) ?></th> <td><?= $block->escapeHtml($order->getBaseToGlobalRate()) ?></td> </tr> <?php endif; ?> <?php if ($baseCurrencyCode !== $orderCurrencyCode && $globalCurrencyCode !== $orderCurrencyCode) : ?> <tr> <th><?= $block->escapeHtml(__('%1 / %2 rate:', $orderCurrencyCode, $baseCurrencyCode)) ?></th> <td><?= $block->escapeHtml($order->getBaseToOrderRate()) ?></td> </tr> <?php endif; ?> </table> </div> </div> <div class="admin__page-section-item order-account-information"> <?php /* Account Information */ ?> <div class="admin__page-section-item-title"> <span class="title"><?= $block->escapeHtml(__('Account Information')) ?></span> <div class="actions"> <?php if ($customerUrl) : ?> <a href="<?= /* @noEscape */ $customerUrl ?>" target="_blank"> <?= $block->escapeHtml(__('Edit Customer')) ?> </a> <?php endif; ?> </div> </div> <div class="admin__page-section-item-content"> <table class="admin__table-secondary order-account-information-table"> <tr> <th><?= $block->escapeHtml(__('Customer Name')) ?></th> <td> <?php if ($customerUrl) : ?> <a href="<?= $block->escapeUrl($customerUrl) ?>" target="_blank"> <span><?= $block->escapeHtml($order->getCustomerName()) ?></span> </a> <?php else : ?> <?= $block->escapeHtml($order->getCustomerName()) ?> <?php endif; ?> </td> </tr> <tr> <th><?= $block->escapeHtml(__('Email')) ?></th> <td><a href="mailto:<?= $block->escapeHtmlAttr($order->getCustomerEmail()) ?>"><?= $block->escapeHtml($order->getCustomerEmail()) ?></a></td> </tr> <?php if ($groupName = $block->getCustomerGroupName()) : ?> <tr> <th><?= $block->escapeHtml(__('Customer Group')) ?></th> <td><?= $block->escapeHtml($groupName) ?></td> </tr> <?php endif; ?> <?php foreach ($block->getCustomerAccountData() as $data) : ?> <tr> <th><?= $block->escapeHtml($data['label']) ?></th> <td><?= $block->escapeHtml($data['value'], ['br']) ?></td> </tr> <?php endforeach;?> <?= $block->getChildHtml('extra_customer_info') ?> </table> </div> </div> </div> </section> <section class="admin__page-section order-addresses"> <div class="admin__page-section-title"> <span class="title"><?= $block->escapeHtml(__('Address Information')) ?></span> </div> <div class="admin__page-section-content"> <div class="admin__page-section-item order-billing-address"> <?php /* Billing Address */ ?> <div class="admin__page-section-item-title"> <span class="title"><?= $block->escapeHtml(__('Billing Address')) ?></span> <div class="actions"><?= /* @noEscape */ $block->getAddressEditLink($order->getBillingAddress()); ?></div> </div> <address class="admin__page-section-item-content"><?= $block->escapeHtml($block->getFormattedAddress($order->getBillingAddress()), $allowedAddressHtmlTags); ?> <div><strong><?php echo __('Custom Billing Text') ?></strong></div> </address> </div> <?php if (!$block->getOrder()->getIsVirtual()) : ?> <div class="admin__page-section-item order-shipping-address"> <?php /* Shipping Address */ ?> <div class="admin__page-section-item-title"> <span class="title"><?= $block->escapeHtml(__('Shipping Address')) ?></span> <div class="actions"><?= /* @noEscape */ $block->getAddressEditLink($order->getShippingAddress()); ?></div> </div> <address class="admin__page-section-item-content"><?= $block->escapeHtml($block->getFormattedAddress($order->getShippingAddress()), $allowedAddressHtmlTags); ?> <div><strong><?php echo __('Custom Shipping Text') ?></strong></div> </address> </div> <?php endif; ?> </div> </section> |
Conclusion:
So now you have successfully added custom text after billing and shipping address in Magento 2 admin sales order view page. Alternatively, you can also Add Custom Text after Billing Address and Shipping Address in Magento 2 Credit Memo PDF.
Share the article with others and let me know if you have any doubts.
Happy Coding!