2

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.enter image description here

Raj
  • 821
  • 8
  • 26
Rv Singh
  • 1,617
  • 15
  • 34

2 Answers2

2
  1. Create custom module Hello_World
  2. 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" />
    &lt;/type&gt;      

</config>

  1. 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;
    }  
    
    }
    
Nagaraju Kasa
  • 5,856
  • 6
  • 53
  • 113
0

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

How to get current customer group id in magento2

Jancy Abraham
  • 2,755
  • 8
  • 46
  • 72
  • Please go through this link "https://magento.stackexchange.com/questions/250625/sql-error-while-adding-any-products-to-category-m2" if idea reply me – Rv Singh Nov 23 '18 at 09:30
  • Sorry @Saniya i don't have any idea. but have you checked magento 2.1.14 default magento locally? – Nagaraju Kasa Nov 26 '18 at 08:54
  • ok, let me check in my-side thanks for reply – Rv Singh Nov 26 '18 at 08:57
  • @NagarajuKasa I need help please go thorough this link "https://magento.stackexchange.com/questions/251650/magento2-category-custom-textarea-with-wysiwyg-editor-attribute-value-blank-iss" – Rv Singh Nov 28 '18 at 14:09
  • @Saniya have you followed this https://inchoo.net/magento-2/add-category-attribute-magento-2/ ? – Nagaraju Kasa Nov 28 '18 at 14:59
  • we have already follow that tutorial – Rv Singh Nov 29 '18 at 04:29
  • let me try from my end get back to you @Saniya – Nagaraju Kasa Nov 30 '18 at 04:27
  • In order summary right side how to move tax in magneto2 – Rv Singh Nov 30 '18 at 06:40
  • @Saniya i have answered for this https://magento.stackexchange.com/questions/251650/magento2-category-custom-textarea-with-wysiwyg-editor-attribute-value-blank-iss . 2nd point is regarding order summery if you posted question in stack can you please share the link – Nagaraju Kasa Nov 30 '18 at 09:08
  • Please go through here 2point "https://magento.stackexchange.com/questions/251949/magento2-tax-not-shows-for-not-logged-in-customer-issue" – Rv Singh Nov 30 '18 at 09:40