'Getting value of div inside a WordPress function

Can anybody help?

I have a div with the ID of 'sum' and need to extract the value and return that in a data array, similar to the below (this code works exactly as I need except I simply need to replace 'Delft Stack Tutorials' with the value of the div).

add_action('woocommerce_thankyou', 'update_post_on_order');

function update_post_on_order($order_id)
{
  $order = wc_get_order($order_id);
  if (!$order->get_id()) {
    return;
  }
    
    $new_balance = "Delft Stack Tutorials";

      $data = array(
        'ID' => 401,
        "meta_input" => array(
          "test_balance" => $new_balance
        )
      );
    
    wp_update_post( $data );

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source