Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
1,205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. add_filter( 'gform_product_info', function( $product_info, $form, $entry ) {
  2. // 6 is the qty field ID of the form you need to change it with your form qty id
  3. if ( rgar( $entry, 6 ) > 2 ) {
  4. $total = get_total($product_info);
  5. $fee = ($total * 0.6);
  6. $product_info = array(
  7. 'products' => array(
  8. array(
  9. 'name' => 'Discounted',
  10. 'price' => $fee,
  11. 'quantity' => 1,
  12. ),
  13. ),
  14. );
  15. } else if ( rgar( $entry, 6 ) > 1 ) {
  16. $total = get_total($product_info);
  17. $fee2 = ($total * 0.7);
  18. $product_info = array(
  19. 'products' => array(
  20. array(
  21. 'name' => 'Discounted',
  22. 'price' => $fee2,
  23. 'quantity' => 1,
  24. ),
  25. ),
  26. );
  27. }
  28.  
  29. return $product_info;
  30. }, 10, 3 );
  31.  
  32.  
  33. function get_total($products) {
  34. $total = 0;
  35. foreach($products["products"] as $product){
  36.  
  37. $price = GFCommon::to_number($product["price"]);
  38. if(isset($product["options"]) && is_array($product["options"])){
  39. foreach($product["options"] as $option){
  40. $price += GFCommon::to_number($option["price"]);
  41. }
  42. }
  43. $subtotal = floatval($product["quantity"]) * $price;
  44. $total += $subtotal;
  45. }
  46. $total += floatval($products["shipping"]["price"]);
  47. return $total;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement