1

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

/public_html/app/design/frontend/base/default/template/checkout/cart/shipping.phtml

How can i give free shipping using script?

0

To do so you can try this way.

di.xml

<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"/>
   </type>
</config>

ShowFreeShipping.php

<?php
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)
         unset($methods[$key]);
     }
  }
 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 '18 at 5:00
  • Please chect my updated answer, I hope it 'll work for you. – Ramkishan Suthar Oct 4 '18 at 5:32
  • 1
    Hi @zus, You should accept the answer if it works for you. It will help others. – Ramkishan Suthar Oct 5 '18 at 7:13

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.