Conditionally hide the node comments via preprocess function I have learned how to hide the display of the author and the creation date of a node, depending on the content of a taxonomy field.
Is it going to hide the comment on the same way?

function mytheme_preprocess_node(&amp;$variables) {

  // check if this is the right content type where the field exists
  if ($variables['node']-&gt;getType() != 'article') {
    return;
  }

  // taxonomy field
  $field = $variables['node']-&gt;field_where_to_publish;

  if (!$field-&gt;isEmpty() &amp;&amp; $field-&gt;entity-&gt;label() == 'public') {

    // How to hide the comment for this entity label?
  }

}
$variables['content']['comment']['#access'] = FALSE;


That should work, assuming you use the default comment field named "comment", otherwise whatever you named it. Comments are just a field, nothing special about them.

You can also check it directly in twig and not print it there.