We need to add extra Cost to shipping method, when customer select one of the input radio button on the custom shipping form.

2 Answers 2


we can add plugin for Magento\Quote\Model\Quote\Address\Rate

<type name="Magento\Quote\Model\Quote\Address\Rate">
    <plugin name="custom_shipping_price" type="<vendor>\<module>\Plugin\Quote\Address\Rate"/>

In <module>\Plugin\Quote\Address\Rate Class add after method on afterImportShippingRate

public function afterImportShippingRate(\Magento\Quote\Model\Quote\Address\Rate $subject, $result, $rate)
    if ($rate instanceof \Magento\Quote\Model\Quote\Address\RateResult\Method) {
        if($result->getCode() == 'custom_shipping_method_code') {
    return $result;

we can change the shipping method price here(<custom_shipping_method_code>) on our <custom_shipping_method_code>.

change the <custom_shipping_method_code> like flatrate_flatrate


Step 1: You can do this by overriding address rate file in your custom module. Step 2: Create Namespace/Module/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\OfflineShipping\Model\Carrier\Flatrate" type="Namespace\Module\Model\OfflineShipping\Carrier\Flatrate" />

Step 3: Modify the as per requirement into your custom file filepath, app\code\Namespace\Module\Model\OfflineShipping\Carrier\Flatrate.php

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.