G2A Many GEOs
SHARE
TWEET

Gravity Forms coupon code - PayPal Standard -one item

redearth May 20th, 2012 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // send non-negative numbers to PayPal Standard
  2. add_filter('gform_paypal_query', 'update_paypal_query', 10, 3);
  3. function update_paypal_query($query_string, $form, $entry){
  4.  
  5.     parse_str($query_string, $query);
  6.  
  7.     $items = 0;
  8.     $amounts = array();
  9.  
  10.     // find out how many items are in the cart
  11.     foreach($query as $key => $value){
  12.         if( strpos($key,"item_name")!==false){
  13.             $items++;
  14.         }
  15.     }
  16.  
  17.     $maketotal = false;
  18.     $newtotal = 0;
  19.  
  20.     // find out if any of those items are negative (discounts, coupons)
  21.     for($i=0;$i<=$items;$i++){
  22.         if($query['amount_' . $i] < 0){
  23.             $maketotal = true;
  24.         }
  25.     }
  26.     // if not, send on to paypal in regular format
  27.     if(!$maketotal){
  28.         return '&' . $query_string;
  29.  
  30.     } else {
  31.         // otherwise,
  32.         for($i=0;$i<=$items;$i++){
  33.             // calculate the grand total
  34.             $newtotal = $newtotal + $query['amount_' . $i];
  35.  
  36.             // remove the negative items
  37.             $query['item_name_' . $i] = '';
  38.             $query['amount_' . $i] = '';
  39.             $query['quantity_' . $i] = '';
  40.         }
  41.         // make one new item that combines all items into one
  42.         $query['item_name_1'] = 'Registration Total';
  43.         $query['amount_1'] = $newtotal;
  44.         $query['quantity_1'] = 1;
  45.  
  46.         $query_string = http_build_query($query, '', '&');
  47.  
  48.         return '&' . $query_string;
  49.     }
  50. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top