2

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.

1 Answer 1

0

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 .

1
  • I want to hide as per Shipping method how can we get that? Commented Jul 19, 2022 at 5:55

Your Answer

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

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