From aca0a8f2d14641fc52b262bac6f84fe93486e691 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Thu, 27 Apr 2017 14:22:58 -0400 Subject: [PATCH] adding dynamically populated discounted total form input adding a new input field to the poster form to add a discounted calculation total to the new field. using a gravity pdf hook to append the data to the form after generation --- functions.php | 57 ++++++++++++++++++++++++------------------ js/app.js | 4 +-- js/custom/pageSetup.js | 4 +-- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/functions.php b/functions.php index 04cc3e5..f5ea1c9 100644 --- a/functions.php +++ b/functions.php @@ -368,31 +368,38 @@ function change_post_content( $form ) { } // loop through the populated fields to calc the qty $quantity = 0; - foreach($populated_fields as $price=>$info){ - $quantity += $info['qty']; - } - - // logic to determine the discount rate, every 4 gets $10 off - if($quantity % 4 === 0){ - $discount_qty = $quantity / 4; - $discount_price = $discount_qty * 10; - $price_total = ($quantity * 10) - $discount_price; - - } else if( $quantity > 4 && $quantity % 4 !== 0){ - $discount_qty = floor($quantity / 4); - $discount_price = $discount_qty * 10; - $price_total = ($quantity * 10) - $discount_price; - - } else if( $quantity < 4){ - $price_total = $quantity * 10; - } - - $new_price = $price_total / $quantity; - - // set the newly calulated price for pdf form - foreach($populated_fields as $price=>$info){ - $_POST[$price] = $new_price; - } +// foreach($populated_fields as $price=>$info){ +// $quantity += $info['qty']; +// } +// +// // logic to determine the discount rate, every 4 gets $10 off +// if($quantity % 4 === 0){ +// $discount_qty = $quantity / 4; +// $discount_price = $discount_qty * 10; +// $price_total = ($quantity * 10) - $discount_price; +// +// } else if( $quantity > 4 && $quantity % 4 !== 0){ +// $discount_qty = floor($quantity / 4); +// $discount_price = $discount_qty * 10; +// $price_total = ($quantity * 10) - $discount_price; +// +// } else if( $quantity < 4){ +// $price_total = $quantity * 10; +// } +// +// $new_price = $price_total / $quantity; +// +// // set the newly calulated price for pdf form +// foreach($populated_fields as $price=>$info){ +// $_POST[$price] = $new_price; +// } } +add_action( 'gfpdf_post_html_fields', function( $entry, $config ) { + if($entry['form_id'] === '2'){ + echo "
DISCOUNTED TOTAL: " . $entry['21'] . "
"; + } + + +}, 10, 2 ); ?> \ No newline at end of file diff --git a/js/app.js b/js/app.js index 2c2caeb..5c80b93 100644 --- a/js/app.js +++ b/js/app.js @@ -91,8 +91,8 @@ $(document).ready(function () { price_total = qty_total * 10; } - $('.ginput_total_2').text('$' + price_total + '.00'); - $('#input_2_15').val(price_total); + $('#input_5_20').text('$' + price_total + '.00'); + $('#input_5_20').val('$' + price_total + '.00'); } $(window).on("load", function(){ diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index 5028757..096a3dd 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -82,8 +82,8 @@ $(document).ready(function () { price_total = qty_total * 10; } - $('.ginput_total_2').text('$' + price_total + '.00'); - $('#input_2_15').val(price_total); + $('#input_5_20').text('$' + price_total + '.00'); + $('#input_5_20').val('$' + price_total + '.00'); } $(window).on("load", function(){ -- 2.17.1