9 – How to change fields order in node ds view?

I am using Drupal 9. My task is to reorder node default display (I am using DS module) fields’ order depends on some conditions. I have tried to do it by hook_ds_pre_render_alter() hook. Here my code

/**
 * Implements hook_ds_pre_render_alter().
*/
function ancestors_main_ds_pre_render_alter(&$layout_render_array, &$context, &$variables) {
 if (!empty($context('bundle')) && $context('bundle') === 'event_and_heritage_tour') {
  foreach($layout_render_array as $region => &$fields) {
    if ($region === 'field_event_and_tour_media') {
      $fields('#weight') = 2;      
     }
    }
   }
 }

Is there any way to solve my problem?