Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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 = 1;
- $amounts = array();
- // find out how many items are in the cart
- foreach($query as $key => $value){
- if( strpos($key,"item_name")!==false){
- $items++;
- }
- }
- $n = 1;// normal items
- // find out if any of those items are negative (discounts, coupons)
- for($i=1;$i<=$items;$i++){
- if($query['amount_' . $i] <= 0){
- $query['discount_amount_cart'] = $query['discount_amount_cart'] + abs($query['amount_' . $i]);
- // clear this discount item
- $query['item_name_' . $i] = '';
- $query['amount_' . $i] = '';
- $query['quantity_' . $i] = '';
- } else {
- // reassign the numbers so don't have any empties (or keep same if $n=$i)
- $query['item_name_' . $n] = $query['item_name_' . $i];
- $query['amount_' . $n] = $query['amount_' . $i];
- $query['quantity_' . $n] = $query['quantity_' . $i];
- $n++;
- }
- }
- for($a=$n;$a<=$items;$a++){
- //clear the remaining items so no duplicates
- $query['item_name_' . $a] = '';
- $query['amount_' . $a] = '';
- $query['quantity_' . $a] = '';
- }
- $query_string = http_build_query($query, '', '&');
- return '&' . $query_string;
- }
Add Comment
Please, Sign In to add comment