Is there any way to override Shipping Price by Special User (Customer Service Team) when they place an order for the customer.

I want to add a text box for the Custom Shipping price which will override existing shipping cost to quote when user will go to the next step.

enter image description here

For Example, I want to make 46.53 to 40.

  • is this shipping method coming from one carrier? – Amit Bera Oct 5 '18 at 7:41
  • Yes amit. It’s coming from one carrier – Abhishek Panchal Oct 5 '18 at 12:12
  • can you please share yours carrier method code? – Amit Bera Oct 8 '18 at 6:30
  • Can you specify which shipping method you want to change rate? – Dhiren Vasoya Oct 9 '18 at 13:52

You need to do code like this. We take example that, you need to price into carrier called "Tablerate".

  1. we need to create di.xml at following location.


    <?xml version="1.0"?>
    <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\Tablerate" type="Vendor\Extension\Model\Carrier\Tablerate" />
  1. create our logic file here.


namespace Vendor\Extension\Model\Carrier;

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

class Tablerate extends \Magento\OfflineShipping\Model\Carrier\Tablerate
    public function collectRates(RateRequest $request)
        //Do your logic before this line and return your custom price.

First, I think you should set the price to depend on the customer inputed.

with function setPrice of \Magento\Quote\Model\Quote\Address\RateResult\Method

The solution is plugin to Magento\Quote\Model\Quote\Address\RateResult\Method and change value of price before set to data['price'];


<type name="Magento\Quote\Model\Quote\Address\RateResult\Method">
        <plugin name="namespace_change_price_of_shipping_rate" type="NameSpace\Module\Plugin\Model\Quote\Address\RateResult\Method"/>


namespace NameSpace\Module\Plugin\Model\Quote\Address\RateResult;

class Method

      protected $_customerSession;
    public function __construct(
        \Magento\Customer\Model\Session $customerSession)
        $this->_customerSession = $customerSession;

     * Round shipping carrier's method price
     * @param string|float|int $price
     * @return $this
    public function beforeSetPrice($subject, $price)
        // @TODO returun inputed price
        return $price;

    public function beforeSetCost($subject, $price)
        // @TODO returun inputed price.
        return $price;

    public function beforeSetData($subject, $key, $value){
        if('price' == $key || 'cost' == $key){
                //@TODO set inputed price to value
        return [$key, $value];

2: Edit your vendor/magento/module-checkout/view/frontend/web/template/shipping-address/shipping-method-item.html:16 file to Add an input for input custom price

<input type="text" attr="'value': customPrice "/>

3: Edit shipping javascript file vendor/magento/module-checkout/view/frontend/web/js/view/shipping.js to add a function that appends custom price to shipping data.

    selectShippingMethod: function (shippingMethod) {
        checkoutData.setSelectedShippingRate(shippingMethod['carrier_code'] + '_' + shippingMethod['method_code']);
        /** @TODO store custom input data to somewhere 
         * for  NameSpace\Module\Plugin\Model\Quote\Address\RateResult\Method 
         * can get and set to value of variable **price** */
        return true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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