In magento2 checkout page i'm using free shipping method and i need to hide free shipping method only for non stocking customer group and rest of all customer group i want to display free shipping method.So anyone please guide me in which file i have to put condition.Please check attached image.
-
can you please clarify non stocking customer group means?– Nagaraju KasaNov 19, 2018 at 12:41
-
Non stocking group menas => Not logged in users?– Nagaraju KasaNov 19, 2018 at 12:43
-
We have created in new customer group name called non stocking.– Rv SinghNov 19, 2018 at 12:44
-
have you tried with cart price rules ? prnt.sc/lk7xu9– Nagaraju KasaNov 19, 2018 at 12:48
-
Actually i don't want to apply free shipping i want to hide free shipping option in checkout page for particular customer groups– Rv SinghNov 19, 2018 at 12:52
2 Answers
- Create custom module
Hello_World
- Create plugin and configure in
di.xml
file,app/code/Hello/World/di.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\OfflineShipping\Model\Carrier\Freeshipping"> <plugin name="disable-freeshipping" type="Hello\World\Model\Carrier\Freeshipping" sortOrder="1" /> </type> </config>
Create model file
app/code/Hello/World/Model/Carrier/Freeshipping.php
<?php namespace Hello\World\Model\Carrier; class Freeshipping{ protected $_checkoutSession; protected $_scopeConfig; protected $_customerSession; public function __construct( \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Customer\Model\Session $customerSession ) { $this->_storeManager = $storeManager; $this->_checkoutSession = $checkoutSession; $this->_scopeConfig = $scopeConfig; $this->_customerSession = $customerSession; } public function afterCollectRates(\Magento\OfflineShipping\Model\Carrier\Freeshipping $freeshipping, $result) { //Magento-2 Log Here $writer = new \Zend\Log\Writer\Stream(BP.'/var/log/magento2.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); //Customer Group ID Here $customerGroupId=$this->_customerSession->getCustomer()->getGroupId(); $logger->info("Free shipping has been calling and customerGroupId ".$customerGroupId); //keep your customer group id here if($customerGroupId === '1'){ return false; } return $result; } }
-
1
-
Please try this code in local instance first and test the scenarios and then confirm the same Nov 19, 2018 at 14:04
-
but I think there are some naming issue in your above code "Create model file app/code/Hello/World/di.xml"– Rv SinghNov 19, 2018 at 14:05
-
Yes @Saniya i have updated now please consider updated answer now Nov 19, 2018 at 14:06
-
@Saniya let me know whether this solution is working fine as you expected? Nov 20, 2018 at 6:54
For this, you need to create a custom shipping method. The below link will helps you to create custom shipping method
https://webkul.com/blog/create-custom-shipping-method-in-magento2/
You can set the condition in the function collectRates in the file app/code/Webkul/Customshipping/Model/Carrier.php
Refer the below link to get customer group
-
Please go through this link "magento.stackexchange.com/questions/250625/…" if idea reply me– Rv SinghNov 23, 2018 at 9:30
-
Sorry @Saniya i don't have any idea. but have you checked magento 2.1.14 default magento locally? Nov 26, 2018 at 8:54
-
-
@NagarajuKasa I need help please go thorough this link "magento.stackexchange.com/questions/251650/…"– Rv SinghNov 28, 2018 at 14:09
-
@Saniya have you followed this inchoo.net/magento-2/add-category-attribute-magento-2 ? Nov 28, 2018 at 14:59