The field group module is no longer storing grouped fields as a fieldset in Drupal 8. It's storing metadata on each group in an array called #fieldgroups
which is used in a pre-render function.
The logic of the module doesn't render the fieldset if all its children elements aren't visible. Hence, you can hide all the children elements to have the same effect. For example:
foreach ($form['#fieldgroups']['group_p_payment']->children as $form_element_id) {
$form[$form_element_id]['#access'] = FALSE;
}
The logic will have to change if you have nested groups, but the approach will remain the same.
Note that the above code can go in a form alter, but you should ensure that your form alter runs after Field Group does its work.
Here is complete working code, for a module named example in the example.module
file:
/**
* Implements hook_module_implements_alter().
*/
function example_module_implements_alter(&$implementations, $hook) {
if ($hook == 'form_alter' && isset($implementations['example'])) {
$hook_implementation = $implementations['example'];
unset($implementations['example']);
$implementations['example'] = $hook_implementation;
}
}
/**
* Implements hook_form_BASE_FORM_ID_alter() for node_form.
*/
function example_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
foreach ($form['#fieldgroups']['group_b_payment']->children as $form_element_id) {
$form[$form_element_id]['#access'] = FALSE;
}
}