Because your customers care about shipping! It is powerful enough to make or break your business because creating the product, offering at best prices and serving great customer experience is not enough. Your way of shipping and delivering products safely to the hands of customers can be the ultimate reason for success. Online shoppers are too picky when it comes to shipping costs and delivery options that you are using. Even sometimes store owners are offering shipping at low cost to increase average order value when the customer is making a bulk purchase or fulfilling some conditions.
Recently we did the same for one of our clients and it will be helpful to other store owners too. So, here is our another blog on “How to Override Product Shipping Prices in Magento 2.
To do the same first we need to create “di.xml” at the following location.
app\code\Vendor\Extension\di.xml
<pre class="lang:default decode:true"> <?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" /> </config> </pre>
Now, we need to create one more file “Tablerate.php” that contains our main logic file for setting up custom shipping price.
app\code\Vendor\Extension\Model\Carrier\Tablerate.php
<pre class="lang:default decode:true"> <?php 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. $shippingPrice = 50; $method->setPrice($shippingPrice); } } </pre>
That’s it, hope this code will help you to Override Product Shipping Price in your Magento 2 Store. You can even use & customize this code according to your need for integrating stylesheet.
Also, let us know if you are facing an issue while implementing using this code, we are happy to help you.
Happy Coding!