// send non-negative numbers to PayPal Standard add_filter('gform_paypal_query', 'update_paypal_query', 10, 3); function update_paypal_query($query_string, $form, $entry){ parse_str($query_string, $query); $items = 0; $amounts = array(); // find out how many items are in the cart foreach($query as $key => $value){ if( strpos($key,"item_name")!==false){ $items++; } } $maketotal = false; $newtotal = 0; // find out if any of those items are negative (discounts, coupons) for($i=0;$i<=$items;$i++){ if($query['amount_' . $i] < 0){ $maketotal = true; } } // if not, send on to paypal in regular format if(!$maketotal){ return '&' . $query_string; } else { // otherwise, for($i=0;$i<=$items;$i++){ // calculate the grand total $newtotal = $newtotal + $query['amount_' . $i]; // remove the negative items $query['item_name_' . $i] = ''; $query['amount_' . $i] = ''; $query['quantity_' . $i] = ''; } // make one new item that combines all items into one $query['item_name_1'] = 'Registration Total'; $query['amount_1'] = $newtotal; $query['quantity_1'] = 1; $query_string = http_build_query($query, '', '&'); return '&' . $query_string; } }