Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Gravity Forms coupon code - PayPal Standard- discount amount

redearth May 20th, 2012 227 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 = 1;
  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.     $n = 1;// normal items
  18.  
  19.     // find out if any of those items are negative (discounts, coupons)
  20.     for($i=1;$i<=$items;$i++){
  21.         if($query['amount_' . $i] <= 0){
  22.  
  23.             $query['discount_amount_cart'] = $query['discount_amount_cart'] + abs($query['amount_' . $i]);
  24.  
  25.             // clear this discount item
  26.             $query['item_name_' . $i] = '';
  27.             $query['amount_' . $i]    = '';
  28.             $query['quantity_' . $i]  = '';
  29.  
  30.         } else {
  31.             // reassign the numbers so don't have any empties (or keep same if $n=$i)
  32.             $query['item_name_' . $n] = $query['item_name_' . $i];
  33.             $query['amount_' . $n]    = $query['amount_' . $i];
  34.             $query['quantity_' . $n]  = $query['quantity_' . $i];
  35.  
  36.             $n++;
  37.         }
  38.     }
  39.     for($a=$n;$a<=$items;$a++){
  40.         //clear the remaining items so no duplicates
  41.         $query['item_name_' . $a] = '';
  42.         $query['amount_' . $a]    = '';
  43.         $query['quantity_' . $a]  = '';
  44.     }
  45.  
  46.     $query_string = http_build_query($query, '', '&');
  47.  
  48.     return '&' . $query_string;
  49. }
RAW Paste Data
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