Magento2 - How to change cart totals label?
-
09-10-2020 - |
Question
I want to modify this label
Its from "checkout.cart.totals" block in magento\vendor\magento\module-checkout\view\frontend\layout\checkout_cart_index.xml
, and I'm pretty sure its this chunk of code that handles the label
<item name="grand-total" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/summary/grand-total</item>
<item name="config" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Order Total</item>
<item name="template" xsi:type="string">Magento_Checkout/cart/totals/grand-total</item>
</item>
</item>
so I changed that chunk of code like so:
<item name="grand-total" xsi:type="array">
<item name="component" xsi:type="string">Magento_Checkout/js/view/summary/grand-total</item>
<item name="config" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Grand Total</item>
<item name="template" xsi:type="string">Magento_Checkout/cart/totals/grand-total</item>
</item>
</item>
I just changed the title from Order Total to Grand Total.
But nothing changed. Front end still shows Order Total. Did I missed something?
Solution
My bad.
Using Knockoutjs context debugger, I can see the template is coming from Magento_Tax/checkout/cart/totals/grand-total
. So the right xml would be magento\vendor\magento\module-tax\view\frontend\layout\checkout_cart_index.xml
and the code to be edited is this:
<item name="grand-total" xsi:type="array">
<item name="component" xsi:type="string">Magento_Tax/js/view/checkout/cart/totals/grand-total</item>
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">Magento_Tax/checkout/cart/totals/grand-total</item>
<item name="exclTaxLabel" xsi:type="string" translate="true">Grand Total Excl. Tax</item>
<item name="inclTaxLabel" xsi:type="string" translate="true">Grand Total Incl. Tax</item>
<item name="title" xsi:type="string" translate="true">Grand Total</item>
</item>
- edit: Found another way to do it without modifying the magento component.
I create this file app\design\frontend\Vendor\theme\Magento_Checkout\layout\checkout_cart_index.xml
with this content
<?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="checkout.cart.totals">
<arguments>
<argument name="jsLayout" xsi:type="array">
<!-- UI component customizations -->
<item name="components" xsi:type="array">
<item name="block-totals" xsi:type="array">
<item name="children" xsi:type="array">
<item name="grand-total" xsi:type="array">
<item name="config" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Grand Total</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
OTHER TIPS
You can also change Order Total label at
Core File:
vendor/magento/module-checkout/i18n/en_US.csv
Theme File:
app/design/frontend/Vendor/theme/Magento_Checkout/i18n/en_US.csv
Change this
"Order Total","Your Custom Title"