3

How to display only "Shipping" text instead of "Shipping(Flat Rate - Fixed)" text in Cart, Checkout and Emails.

enter image description here

1

There are several options for changing the visible text. Here are two clear options.

  • Magento's translation system. I will direct you to the M2 Developer Documentation. Essentially, you will create a .csv file in a special location. This will let you make statements like "Shipping (Flat Rate - Fixed)","Shipping", instructing Magento to replace every occurrence of the left string with the right string.

  • In your theme, override the .phtml template that contains the string. Again, I will direct you to Magento's M2 documentation on adding templates to your theme. Once you have a working theme, if you include a .phtml at the correct location, Magento will use your template instead of the parent theme's template.

  • 1
    While this is true for most texts in Magento, here it does not work. These values are built dynamically in the shipping carrier models (the implementations of \Magento\Shipping\Model\Carrier\AbstractCarrierInterface::collectRates()), based on the configured carrier title ("Flat Rate") and method title ("Fixed"). There is no translation involved and no template contains the string. – Fabian Schmengler Feb 17 '17 at 9:10
1

The string "Flat Rate - Fixed" is generated based on the shipping method configuration in \Magento\Checkout\Model\Type\Onepage::saveShippingMethod():

$shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();
$shippingAddress->setShippingDescription(trim($shippingDescription, ' -'));

Later, it is appended to "Shipping" in \Magento\Quote\Model\ResourceModel\Quote\Address\Attribute\Frontend\Shipping::fetchTotals():

$title = __('Shipping & Handling');
if ($address->getShippingDescription()) {
    $title .= sprintf(' (%s)', $address->getShippingDescription());
}

As you can see, if getShippingDescription() is empty, nothing is added (i.e. no empty brackets), so you can get your desired result by unsetting the shipping description.

$address->setShippingDescription('');

This can be done in several places, IMHO the best option is to do it right before the shipping address is saved:

  • using the event sales_quote_address_save_before OR
  • using a "before" plugin for \Magento\Quote\Model\Quote\Address::save()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.