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>
$order->getShippingAddress()->getCountryId();
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();
$customerid=$order->getCustomerId()
$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.