I have to give free shipping order over 1000 and zipcode range between 600001 to 600010, i am using webshop matrix rate for shipping method, in this case, shopping cart pricing rule not working free shipping, so i have to plan for do custom PHP code for giving free shipping, My condition how can i give condition like subtotal is equal or greater than 1000 and zipcode between 600001 and 600010 in


How can i give free shipping using script?

1 Answer 1


To do so you can try this way.


<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <type name="Magento\Quote\Api\ShippingMethodManagementInterface">
      <plugin name="change_shipping method" type="VendorName\ModuleName\Plugin\ShowFreeShipping"/>


namespace VendorName\ModuleName\Plugin;

class ShowFreeShipping

 public function __construct(\Magento\Checkout\Model\Session $checkoutSession){
   $this->checoutSession $checkoutSession;

 public function afterEstimateByAddress(Magento\Quote\Api\ShippingMethodManagementInterfac $subject, $methods)
  $quote = $this->checoutSession->getQuote();
  $postCode = $quote->getShippingAddress()->getPostcode();
  $totals = $quote->getTotals();      
  $subtotal = $totals['subtotal']['value'];
  foreach($methods as $key => &$method)
     if($method->getMethodCode() == 'freeshipping')
     //set condition whenever you want to show freeshipping or not
       if($sbutotal <= 1000)
 return $methods;

Please make sure that you have enabled freeshipping from admin. Let me know if you need further assistance.

  • Here, where i can i give postal-code condition?
    – zus
    Oct 4, 2018 at 5:00
  • Please chect my updated answer, I hope it 'll work for you. Oct 4, 2018 at 5:32
  • 1
    Hi @zus, You should accept the answer if it works for you. It will help others. Oct 5, 2018 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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