Hi pmagony,
You can use the following snippet in your child theme’s functions.php.
To be honest, i haven’t tested it but it should do the job. In product_id you should put the id of the product you are interested and in $group_id the id of the group you want to add the user to.
add_action( 'woocommerce_payment_complete', 'gt_add_user_to_group', 10, 1);
function gt_add_user_to_group( $order_id ) {
$order = new WC_Order( $order_id );
$myuser_id = $order->user_id;
$user_info = get_userdata( $myuser_id );
$items = $order->get_items();
foreach ( $items as $item ) {
if ($item['product_id']==24) {
Groups_User_Group::create( array( 'user_id' => $user_id, 'group_id' => $group_id ) );
}
}
}
Kind regards
George