Magento – Change Shipping Method Name programmatically

magento2programmaticallyshippingshipping-methods

i want to change the Shipping Method Name programmatically in some cases.
enter image description here

(This store is in german)

So I want to change "Versand oder Abholung" to another different text depending on the case.

How can I manipulate this text?

I have found the .html file which contains this div. (Maybe this will help?)
app\design\frontend\MyStore\MyStoreTheme\Magento_Checkout\web\shipping.html

<form class="form methods-shipping" id="co-shipping-method-form" data-bind="submit: setShippingInformation" novalidate="novalidate">
            <div id="checkout-shipping-method-load">
                <table class="table-checkout-shipping-method">
                    <thead>
                        <tr class="row">
                            <th class="col col-method" data-bind="i18n: 'Select Method'"></th>
                            <th class="col col-price" data-bind="i18n: 'Price'"></th>
                            <th class="col col-method" data-bind="i18n: 'Method Title'"></th>
                            <th class="col col-carrier" data-bind="i18n: 'Carrier Title'"></th>
                        </tr>
                    </thead>
                    <tbody>



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

Any ideas? 😉

Best Answer

Ok I have found a solution.

use Magento\Quote\Model\Quote\Address\RateRequest;

    class Tablerate extends \Magento\OfflineShipping\Model\Carrier\Tablerate
    {
        public function collectRates(RateRequest $request)
        {
            $result = $this->_rateResultFactory->create()
            $method = $this->_resultMethodFactory->create();
            $method->setMethod('bestway');
            $method->setMethodTitle("test1234");
            $result->append($method);
            return $result;
        }
    }
Related Topic