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
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;
}
}
-
I can't find a path \Magento\Quote\Model\Quote\Address\RateResult\Method in my app directory. I'm using the Novetty Theme.gx2g– gx2g2017年10月03日 17:21:42 +00:00Commented 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– gx2g2017年10月03日 17:39:15 +00:00Commented 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.Aaron Allen– Aaron Allen2017年10月03日 19:12:48 +00:00Commented 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– gx2g2017年10月03日 19:25:18 +00:00Commented Oct 3, 2017 at 19:25
-
vendor > magento > module-quote > Model > Quote > Address > RateResult > method.phpgx2g– gx2g2017年10月03日 21:24:54 +00:00Commented Oct 3, 2017 at 21:24