i want to change customer group on one-page checkout based on checkout address .

Basically two type of customer group : Indian Customer , Outside India, if checkout country is other than India customer groups should auto switch to Outside India

issue : can same be applied for guest customer (non logged in users also).

I am using tier price for products based on Customer Group.

Please help me with way to do same .

  • I think you should change your customer flow. Because run time it might be difficult to change the customer group and apply the correct tier price. – Nits Apr 12 at 11:44
  • @Nits : i want this thing is it possible that way auto switch store based on country : magento.stackexchange.com/questions/310183/… – user1799722 Apr 12 at 11:45

Use event :- here is event : etc/frontend/events.xml "checkout_onepage_controller_success_action"

public function execute(\Magento\Framework\Event\Observer $observer ) {        

//Get order details
$order = $observer->getEvent()->getOrder(); <br>
$guestCustomer = $order->getCustomerIsGuest(); <br>
$groupId  = $order->getCustomerGroupId(); <br>

Check for the country id and then inject customer class

private $customerRepository;

public function __construct(
    \Magento\Framework\App\RequestInterface $request,
     CustomerRepositoryInterface $customerRepository
    $this->_request = $request;
    $this->customerRepository = $customerRepository;


    $id = $observer->getEvent()->getCustomer()->getId();
    $customer = $this->customerRepository->getById($customerid);

//Set customer to the group id as per requirement $customer->setGroupId($group_id);

Change code as per requirement , basically this is the logic.

| improve this answer | |
  • can customer group be set for guest user – user1799722 Apr 12 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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