Skip to content

Instantly share code, notes, and snippets.

@geekontheroad
Last active April 19, 2024 04:26
Show Gist options
  • Save geekontheroad/7356779c711d30426c437f0f75957774 to your computer and use it in GitHub Desktop.
Save geekontheroad/7356779c711d30426c437f0f75957774 to your computer and use it in GitHub Desktop.
/**
* This is a JavaScript Snippet for the Gravity Forms Live Summary Pro add-on.
* It allows you to overwrite the dispplayed total in the summary
*
* @param string total_formatted This is the formatted total according to the form currency
* @param string total_not_formatted This is the non formatted total. Use this for any calculations
* @param string formId This is the current form id
* @param string type This is the type of the summary and will either be side or the summary field ID
*
* @return string Return the HTML for the total to display
***/
gform.addFilter( 'gotrgf_summary_total', function(total_formatted , total_not_formatted, formId, type){
// Parse the unformatted total to be used in calculations
let originalTotal = parseFloat(total_not_formatted);
if (isNaN(originalTotal)) {
originalTotal = 0;
}
// Define the multiplier
let multiplier = 1.3;
// Calculate the adjusted total
let adjustedTotal = originalTotal * multiplier;
// Format the adjusted total
let adjustedTotalFormatted = gotrLiveSummaries.toMoney( adjustedTotal );
// Create the range string
let priceRange = total_formatted + " - " + adjustedTotalFormatted;
return priceRange;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment