fpdf - Migrate a php function from one case to another in the same file

one text

My developer left me out to dry and while im able to learn pretty quickly, actually adding code to excisiting piece of code is a struggle while reading the code makes sort of sense. My business got hit by corona and this piece of code is part of my core business. I have to solve this and sadly on my own account as im willing to pay if i had the recources.

I guess this is a very basic question for all but beginners but i'd love to understand it. Been spending alot of time just reading the code and now its time for help.

This piece of code

case 'Summary list':
    foreach ( $order_ids as $order_id ) {
        $user_id = get_post_meta($order_id, '_customer_user', true);
        $groups_user = new Groups_User( $user_id );
        $orders_group[$groups_user->groups[0]->group->name][$user_id][] = $order_id;
    }

    $i = 1;
    foreach ($orders_group as $group => $users) {

        // Group name
        $formater->custom_header($group);
        // Table header
        $formater->table_header();

Displays the group that the user is in on a PDF. Now i know that the foreach part defines the formatter part. the part in particulair is the

// Group name
$formater->custom_header($group);

Now in the same file i need to display that same group name in the following sequence

case 'Delivery note':
    foreach ( $order_ids as $order_id ) {
        $order = wc_get_order( $order_id );
        $user_id = $order->get_user_id();
        if(array_key_exists($order->get_user_id(), $orders_group)) {
            $orders_group[$user_id]['order_ids'][] = $order_id;
        } else {
            $orders_group[$user_id]['order'] = $order;
            $orders_group[$user_id]['order_ids'][] = $order_id;
        }
    }
    $og_count = count($orders_group);
    $og_i = 1;
    foreach ($orders_group as $user_id => $data) {

        // Delivery header
        $formater->delivery_header();
        // Client name
        $formater->custom_header($data['order']
                 ->get_formatted_shipping_full_name(), 5);
        // Client address
        $address = join( ", ", array_filter( array( 
                        $data['order']->get_shipping_address_1(), 
                        $data['order']->get_shipping_address_2(), 
                        $data['order']->get_shipping_city(), 
                        $data['order']->get_shipping_postcode() ) 
                        )
        );
        $formater->custom_header($address, 10);
        // Group name
        $formater->custom_header($group);
        // Table header
        $formater->table_header(); 

Now ive already put the

// Group name
$formater->custom_header($group);

part in there but i am unable to define it in the upper part.

Is someone willing to show me how i can get this to work and possibly explain it since i really like understanding it aswelll.

Edit: https://imgur.com/a/wKPDaM7

The "Registerd" part is what the

// Group name
        $formater->custom_header($group); prints.

In the 2nd image, the blue line, thats where i want that to appear aswell.

Source