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?
1 Answer 1
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– zus2018年10月04日 05:00:27 +00:00Commented Oct 4, 2018 at 5:00
-
Please chect my updated answer, I hope it 'll work for you.Ramkishan Suthar– Ramkishan Suthar2018年10月04日 05:32:07 +00:00Commented Oct 4, 2018 at 5:32
-
1Hi @zus, You should accept the answer if it works for you. It will help others.Ramkishan Suthar– Ramkishan Suthar2018年10月05日 07:13:22 +00:00Commented Oct 5, 2018 at 7:13
Explore related questions
See similar questions with these tags.