Create a custom smartcode in Fluent form to display the total Donation amount

Fluent forms have custom smartcodes for showing dynamic data as an input field's default value. By default, you will get a wide range of dynamic smart-codes like current user info, current embedded post information, dynamic dates, cookie value, URL get parameters, Browser information, IP address, etc.
You can also create your own custom smartcodes in Fluent forms. Here is a real use case of custom SmartCode that you can create to show the total donation amount anywhere within your form. Please note that you have to create a donation form and take payments using PayPal or Stripe in order for the code to work./*
* Total Donation Amount
add_filter('fluentform_editor_shortcodes', function ($smartCodes) {
$smartCodes[0]['shortcodes']['{total_donation_amount}'] = 'Total Donation Amount';
return $smartCodes;

add_filter('fluentform_editor_shortcode_callback_total_donation_amount', function ($value, $form) {

$current_entries = wpFluent()->table('fluentform_submissions')
->where('form_id', $form->id)
->where('payment_status', 'paid')

$total_payments = 0;

foreach ($current_entries as $key => $value) {
$total_payments += (($value->payment_total)/100);

return $total_payments;
}, 10, 2);
You can just add the code to the functions.php file of your theme or use a code snippets plugin to add this code. Afterward, you would see an option with the name Total Donation Amount within the shortcodes dropdown in the Form. 
The code will automatically calculate the total payment or donation amount from the previous entries and display it in the form where you have added the shortcode.