0

I would like to change the shipping method title from "Priority Mail 1-Day" to "Priority Mail"

how do I target this cleanly?

 <td class="col col-method" data-bind="text: method.method_title, attr: {'id': 'label_method_' + method.method_code + '_' + method.carrier_code}"></td>
 <td class="col col-carrier" data-bind="text: method.carrier_title, attr: {'id': 'label_carrier_' + method.method_code + '_' + method.carrier_code}"></td>
</tr>

This is Magento 2 and this data is displayed after a click event on a radio button. I'm thinking I might be able to do this a dirty way and use javascript to overwrite the string value.

$(document).ready(function(){
 $('#formA input[type=radio]').click(function(){
 alert(this.value);
 });
});

But I'm not sure that is the best approach.

asked Sep 29, 2017 at 18:57

1 Answer 1

3

You can make a plugin for the \Magento\Quote\Model\Quote\Address\RateResult\Method class, like the following:

namespace Vendor\Module\Plugin;
use Magento\Quote\Model\Quote\Address\RateResult;
class PluginName
{
 public function afterSetPrice($subject)
 {
 if ( $subject->getMethodTitle() === "Priority Mail 1-Day" ) {
 $subject->setMethodTitle("Priority Mail");
 }
 return null;
 }
}
answered Oct 2, 2017 at 23:31
6
  • I can't find a path \Magento\Quote\Model\Quote\Address\RateResult\Method in my app directory. I'm using the Novetty Theme. Commented Oct 3, 2017 at 17:21
  • This didn't work I found the directory path in the vendor folder. made the changes and did a full cache. Commented Oct 3, 2017 at 17:39
  • The problem may be that the method title in the if statement isn't a match, copy exactly what appears in the checkout. I can confirm that this approach does work because I use it myself. Commented Oct 3, 2017 at 19:12
  • I am putting it in the "class Method extends AbstractResult" class at the bottom and I checked the string it's a match completely. am I doing this wrong? Commented Oct 3, 2017 at 19:25
  • vendor > magento > module-quote > Model > Quote > Address > RateResult > method.php Commented Oct 3, 2017 at 21:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.