I created one custom field in sales_order
table, field name is mycstfield
.
I save my value in that field sucessfully when order is placed.
Now, I want to send that field value in following places.
- Order Email (From Admin)
- Inoive Email and Invoice Print (PDF)
- Shipment Print
- Credit Memo Email and Credit Memo Print (PDF)
Can Any one have idea about this, How can I do this.
Best Answer
I give my answer about order email. Other emails and pdf should works with the same logic.
You have to look at
\vendor\magento\module-sales\view\frontend\layout\sales_email_order_items.xml
where the block with class
Magento\Sales\Block\Order\Email\Items
has the template\vendor\magento\module-sales\view\frontend\templates\order\items.phtml
In this template the line
<?php echo $block->getChildHtml('order_totals') ?>
calls the block with totals (always defined insales_email_order_items.xml
)This template starts with
where
$block
is aMagento\Sales\Block\Order\Totals
instance.Then, to add your custom field to totals, try to write a plugin related to one public method of this class, i think you could choose
addTotal()
oraddTotalBefore()
, in this way your custom field will be added to$this->_totals
array and it will be printed from the foreach loop.