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.

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;
    }
}
6
  • I can't find a path \Magento\Quote\Model\Quote\Address\RateResult\Method in my app directory. I'm using the Novetty Theme.
    – gx2g
    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.
    – gx2g
    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?
    – gx2g
    Commented Oct 3, 2017 at 19:25
  • vendor > magento > module-quote > Model > Quote > Address > RateResult > method.php
    – gx2g
    Commented Oct 3, 2017 at 21:24

Your Answer

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

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