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?

asked Oct 3, 2018 at 8:42

1 Answer 1

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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.