Magento – how to get customer group id from last order id in magento 2

event-observermagento2

I want to change customer group after placing an order so I need Customer Group id which can be update in observer . How to achieve it?

Best Answer

If you have Order object then you can that customer group by

$order->getCustomerGroupId();

If want to change it the use

 $order->setCustomerGroupId('New_Your_Group_id');
 $order->_getResource()->saveAttribute($order, 'customer_group_id');