How to change Shipping & Handling charges to custom text on order email magento 2
-
17-03-2021 - |
Question
We need to display the shipping amount to static text "TBD" To be decided.
I have narrow down to this file vendor/magento/module-sales/Block/Order/Totals.php
Line no:124
if (!$source->getIsVirtual() && ((double)$source->getShippingAmount() || $source->getShippingDescription())) {
$this->_totals['shipping'] = new \Magento\Framework\DataObject(
[
'code' => 'shipping',
'field' => 'shipping_amount',
//'value' => $this->getSource()->getShippingAmount(),
'value' => 'TBD',
'label' => __('Shipping & Handling'),
]
);
}
Solution
You can override this file in your custom theme.
vendor/magento/module-sales/view/frontend/templates/order/totals.phtml
here
app/design/frontend/Vendor/Theme/Magento_Sales/view/frontend/templates/order/totals.phtml
And update content like this ..
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* @var $block \Magento\Sales\Block\Order\Totals
* @see \Magento\Sales\Block\Order\Totals
*/
?>
<?php foreach ($block->getTotals() as $_code => $_total) : ?>
<?php if ($_total->getBlockName()) : ?>
<?= $block->getChildHtml($_total->getBlockName(), false) ?>
<?php else :?>
<tr class="<?= $block->escapeHtmlAttr($_code) ?>">
<th <?= /* @noEscape */ $block->getLabelProperties() ?> scope="row">
<?php if ($_total->getStrong()) : ?>
<strong><?= $block->escapeHtml($_total->getLabel()) ?></strong>
<?php else : ?>
<?= $block->escapeHtml($_total->getLabel()) ?>
<?php endif ?>
</th>
<?php if($_code == 'shipping'): ?>
<td <?= /* @noEscape */ $block->getValueProperties() ?> data-th="<?= $block->escapeHtmlAttr($_total->getLabel()) ?>">
<?php echo "TBD"; ?>
</td>
<?php else: ?>
<td <?= /* @noEscape */ $block->getValueProperties() ?> data-th="<?= $block->escapeHtmlAttr($_total->getLabel()) ?>">
<?php if ($_total->getStrong()) : ?>
<strong><?= /* @noEscape */ $block->formatValue($_total) ?></strong>
<?php else : ?>
<?= /* @noEscape */ $block->formatValue($_total) ?>
<?php endif?>
</td>
<?php endif; ?>
</tr>
<?php endif; ?>
<?php endforeach?>
Hope this will help you!
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange