How to hide empty fieldset, but leave prefix and suffix in place?
The easiest way would be to wrap the fieldset itself in another element.

$fieldset_wrapper = array(
  '#prefix' =&gt; '&lt;div class="wrapper"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
);

$fieldset_wrapper['fieldset'] = array(
  '#type' =&gt; 'fieldset',
  '#access' =&gt; FALSE,
);


As you might expect, setting #access to false will prevent an element from being rendered at all.