1 year ago
#360464
sylargaf
GravityForms Altering Grand Total?
I am trying to work some logic around to manipulate the grand total in a GravityForm form before it gets sent to the payment processor. I can't for the life of me figure out how to do it though. I have a calculation field that dynamically sets itself to a discount, my issue is apparently actually getting the finaltotal to recognize this amount. The code for the calculation I have right now (with the switch case omitted):
// Custom Form Logic to Change Total Base on Membership Rates
add_filter( 'gform_calculation_result', function( $result, $formula, $field, $form, $entry ) {
// do stuff
if ($form['id'] == 28 && $field['id']== 107){
$membershipLevel = $_COOKIE['memberlevel'];
$discountAmount = setFieldsPHP($membershipLevel);
print_r($result);
if ($result >= $discountAmount){
$result = $result - $discountAmount;
print_r("FINAL TOTAL: " . $result . ' WITH DISCOUNT OF: ' . $discountAmount);
}
else {
$result = ($result - $result) * -1;
print_r('<BR> FINAL TOTAL SHOULDVE BEEN: 500 - ' . $result . ' WITH DISCOUNT OF: ' . $discountAmount);
}
}
return $result;
}, 10, 5 );
Which this "works". The print_r's display the right thing upon form submission. However I seem to be missing that final step that lets me actually apply this discount to the grand total and get it to effect. Any idea what i'm missing?
Thanks!
php
wordpress
gravityforms
0 Answers
Your Answer