Remove My billing and shipping address are the same checkbox in checkout based on customer group condition in Magento2. When Retail customer is logged in then remove "My billing and shipping address are the same" checkbox otherwise it should be come in checkout page.

you need to override magento_rootdirectory/vendor/magento/module-checkout/view/frontend/web/js/view/billing-address.js .

create custom module .

add di.xml file for frontend , app/code/Vendor/Module/etc/frontend/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\Checkout\Model\CompositeConfigProvider">
        <arguments>
            <argument name="configProviders" xsi:type="array">
                <item name="additional_block_config_provider" xsi:type="object">Vendor\Module\Model\Usergroup</item>
            </argument>
        </arguments>
    </type>
</config>

add Usergroup class at Vendor\Module\Model

<?php

namespace Vendor\Module\Model;

use Magento\Checkout\Model\ConfigProviderInterface;
use \Magento\Customer\Model\Session;
use \Magento\Customer\Model\Group;

class Usergroup implements ConfigProviderInterface
{

    public $customersession;
    public $customergroup;

    public function __construct(Session $customersession,Group $customergroup)
    {
        $this->customersession = $customersession;
        $this->customergroup = $customergroup;
    }

    public function getConfig()
    {
        $customerSession = $this->customersession;

        $groupID = $customerSession->getCustomer()->getGroupId();
        $groupName = $this->customergroup->load($groupID);
        $groupname = $groupName->getCode();


        return [
            'GroupName' => [
                'Name' =>$groupname
            ],
        ];
    }
}

and override billing-address.js file and at line no 115 inside the function canUseShippingAddress()

put this line

if(window.checkoutConfig.GroupName.Name == 'Retailer'){ return false; }

I have not tested this code . Please let me know for any issue I will be happy to help .

I have assumed that customer group name as Retailer;

Hope this helps .

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.