I am developing M2 store for a company that just serves only for domestic users. I recently bought the Amasty Inventory module and made the domestic cities.(No shipping available to the countries different) ) I have two logical pattern where I have no idea to start off with..

Ar01 If total cart price is greater than X amount, free delivery available within city 1 to city 15, even if the cart price is lower than X amount(in city 1 to city 15) that he will have to pay L amount(A fixed rate).

Ar02 even if the cart price greater or lower than X amount if he's not entitled the upon city list(city 1 to city 15) that he'll have to pay for shipping L amount(The fixed rate]

I am using Magento 2.2.2

if someone has an idea how to start off this module please let me know in real quick

  • You can use webshopapps matrixrate which provides you the options you needed. This is the extension url: marketplace.magento.com/webshopapps-module-matrixrate.html Commented Sep 4, 2018 at 7:37
  • I tried this one out but earlier, seems way too behind for actual working. highly recommended not to use this
    – Gayashan
    Commented Sep 4, 2018 at 12:16
  • I think matrixrate perfect is this can you share your csv which we use in matrixrate Commented Sep 4, 2018 at 12:33
  • @PrashantBarot I tried the mentioned module, the problem I'm facing is flat rate I set up from backend includes no shipping cost at " Order summary"
    – Gayashan
    Commented Sep 6, 2018 at 8:49

2 Answers 2


What I understand from your question is you wanted to set shipping amount to 0 if some specific conditions matches .

You can override a collect method in your custom module and can set shipping amount to 0 off course after checking some conditions .

create some custom module Custom/Shippingamount

add registration.php


add module.xml file inside Custom/Shippingamount/etc directoy

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <module name="Custom_Shippingamount" setup_version="0.0.1"/>

add sales.xml file inside Custom/Shippingamount/etc directoy

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/sales.xsd">
    <section name="quote">
        <group name="totals">
            <item name="shipping_amount" instance="Custom\Shippingamount\Model\RemoveShippingPrice" sort_order="510"/>

now create RemoveShippingPrice.php file inside Custom/Shippingamount/Model directory where we are going to set the shipping price to 0 .


namespace Custom\Shippingamount\Model;

use \Magento\Quote\Model\Quote\Address\Total\AbstractTotal;
use \Magento\Quote\Model\Quote;
use \Magento\Quote\Api\Data\ShippingAssignmentInterface;
use \Magento\Quote\Model\Quote\Address\Total;
use \Magento\Checkout\Model\Cart;

class RemoveShippingPrice extends AbstractTotal

    protected  $cart;

    public function __construct(Cart $cart)
        $this->cart = $cart;

     * @param Quote                       $quote              quote
     * @param ShippingAssignmentInterface $shippingAssignment shipping
     * @param Total                       $total              total
     * @return $this
    public function collect(
        Quote $quote,
        ShippingAssignmentInterface $shippingAssignment,
        Total $total
    ) {
        parent::collect($quote, $shippingAssignment, $total);

         * you can check your conditions
         * here or add some logic when to
         * make the shipping amount to 0

        $subTotal = $this->cart->getQuote()->getSubtotal();

       //you can check here subtotal is greater than or less than your x amount 

        $amount = $quote->getShippingAddress()->getShippingAmount();
        $total->addTotalAmount($this->getCode(), -$amount);
        $total->addBaseTotalAmount($this->getCode(), -$amount);

        return $this;

     * This function will fetch the quote details
     * @param Quote $quote quote
     * @param Total $total total
     * @return array|null
    public function fetch(Quote $quote, Total $total)
        $result = null;
        $amount = $total->getDiscountAmount();
        if ($amount != 0) {
            $description = $total->getDiscountDescription();
            $result = [
                'code' => $this->getCode(),
                'title' => $description,
                'value' => $amount
        return $result;
  • That really seems to be working. but if you could little bit more clarify the logic where the conditions are met true. plus this not a discount but a fixed rate for the store till the store exists alive.
    – Gayashan
    Commented Sep 4, 2018 at 12:25
  • @Gayashan yes this is not a discount I have just copy pasted the code from one of my custom module to give you with an idea about how you can remove the shipping rate . I guess you can get a cart total and check the conditions .
    – Mac
    Commented Sep 4, 2018 at 12:39
  • please check the updated code .
    – Mac
    Commented Sep 4, 2018 at 13:11
  • I tried the module on my local project. no luck "Sorry, no quotes are available for this order at this time" this error persists
    – Gayashan
    Commented Sep 5, 2018 at 7:53
  • @Gayashan please check this link hope it will help you - help.onestepcheckout.com/knowledge_base/topics/shipping-methods also check magento.stackexchange.com/questions/149586/…
    – Mac
    Commented Sep 6, 2018 at 15:05

I'm not familiar with the module you've mentioned but this is something you can do using Magento 2's table rates feature.

Step 1: add the cities manually to the end of directory_country_region table with ID, 'COUNTRYCODE','REGIONCODE','Region/city name' format for example 999, 'US','KS','Kansas' .

Step 2: enable table rate: Store -> Configuration -> Store view:Main Website -> Sales -> Shipping Method -> Table Rates:

  • Enabled: Yes
  • Condition: Price vs Destination

Export CSV to download the stock table rate. Edit it.

Ar01: for each city from 1 to 15, you need to add 2 lines:


This translates to: pay L for shipping to REGION if total is between 0 and X, free shipping ( fee = 0 ) if total is higher than X.

Ar02: add one line:


( For every other regions in COUNTRY, shipping is fixed at L )

Step 3: upload the edited csv using Import button, edit Title and Method name for store view, then Save Config -> Refresh cache.

  • I don't have a good feeling touching the core data base table for the sake of compatibility.
    – Gayashan
    Commented Sep 5, 2018 at 10:14
  • Only possible conflict is if the table already has regions with the same REGIONCODE in the same country as the one you want to add. Just make sure your new REGIONCODEs are unique and you're good. Here's a guide. Here's sample query I used to add regions in my country.
    – Madn3ss795
    Commented Sep 5, 2018 at 12:02

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.