So I am trying to use a hook to add change the price.
here is my code
add_filter("gform_pre_submission_filter", "change_price");
function change_price($form){
$price = $_POST["input_2"]; //player 1 email
$coupon = trim( $_POST['input_6'] );
$codes = array(
'27' => 'abc27',
'25' => 'def25',
'23' => 'xyz23',
'21' => 'abc21',
'19' => 'def19',
'17' => 'xyz17',
'15' => 'abc15',
'13' => 'def13',
'11' => 'zyx11',
'9' => 'abc9'
);
$discounts = array_flip($codes);
if( !empty($coupon) && in_array($coupon, $codes) )
{
if( $form["input_3"] == 'Regular')
{
//$form["input_3"] == 'Regular|'.$discounts[$coupon];
}
else
{
//$form["input_3"] == 'Large|'.$discounts[$coupon];
}
}
//var_dump($form['fields']);
//echo $form['fields'][0]['choices'][0]['price'];
//exit;
//returning modified form object
foreach($form["fields"] as &$field){
if($field["id"] == 3){
$field["basePrice"] = '$'.$discounts[$coupon];
$field['choices'][0]['price'] = '$'.$discounts[$coupon];
$field['choices'][1]['price'] = '$'.$discounts[$coupon];
//echo "yes";
}
//var_dump($field);
//exit;
}
//$form['fields'][0]['choices'][0]['price'] = '$'.$discounts[$coupon];
//$form['fields'][0]['choices'][1]['price'] = '$'.$discounts[$coupon];
//var_dump($form['fields']);
//exit;
return $form;
}
here is the form:
https://www.autoeye.org/test
If I dump the form variable the values get changed, but now I'm not sure if they are the values I'm supposed to be changing.
If I just submit the form, it's like nothing happened.
I have most of it commented out because I'm trying to trouble shoot.
I don't know where I'm giong wrong. Please help.
If I for example try the coupon code for $15 it returns this:
array(11) {
[0]=>
array(56) {
["adminLabel"]=>
string(0) ""
["adminOnly"]=>
string(0) ""
["allowsPrepopulate"]=>
bool(false)
["defaultValue"]=>
string(0) ""
["description"]=>
string(0) ""
["content"]=>
string(0) ""
["cssClass"]=>
string(0) ""
["errorMessage"]=>
string(0) ""
["id"]=>
int(3)
["inputName"]=>
string(0) ""
["isRequired"]=>
bool(true)
["label"]=>
string(11) "Choose Size"
["noDuplicates"]=>
string(0) ""
["size"]=>
string(6) "medium"
["type"]=>
string(7) "product"
["postCustomFieldName"]=>
string(0) ""
["displayAllCategories"]=>
bool(false)
["displayCaption"]=>
string(0) ""
["displayDescription"]=>
string(0) ""
["displayTitle"]=>
string(0) ""
["inputType"]=>
string(6) "select"
["rangeMin"]=>
string(0) ""
["rangeMax"]=>
string(0) ""
["calendarIconType"]=>
string(0) ""
["calendarIconUrl"]=>
string(0) ""
["dateType"]=>
string(0) ""
["dateFormat"]=>
string(0) ""
["phoneFormat"]=>
string(0) ""
["addressType"]=>
string(0) ""
["defaultCountry"]=>
string(0) ""
["defaultProvince"]=>
string(0) ""
["defaultState"]=>
string(0) ""
["hideAddress2"]=>
string(0) ""
["hideCountry"]=>
string(0) ""
["hideState"]=>
string(0) ""
["inputs"]=>
NULL
["nameFormat"]=>
string(0) ""
["allowedExtensions"]=>
string(0) ""
["captchaType"]=>
string(0) ""
["page_number"]=>
string(0) ""
["captchaTheme"]=>
string(0) ""
["simpleCaptchaSize"]=>
string(0) ""
["simpleCaptchaFontColor"]=>
string(0) ""
["simpleCaptchaBackgroundColor"]=>
string(0) ""
["failed_validation"]=>
string(0) ""
["productField"]=>
string(0) ""
["enablePasswordInput"]=>
string(0) ""
["maxLength"]=>
string(0) ""
["enablePrice"]=>
bool(true)
["basePrice"]=>
string(3) "$15"
["disableQuantity"]=>
bool(false)
["formId"]=>
int(1)
["pageNumber"]=>
int(1)
["conditionalLogic"]=>
bool(false)
["choices"]=>
array(2) {
[0]=>
array(4) {
["text"]=>
string(18) "Regular 13" x 2.5""
["value"]=>
string(7) "Regular"
["isSelected"]=>
bool(true)
["price"]=>
string(3) "$15"
}
[1]=>
array(4) {
["text"]=>
string(14) "Large 13" x 4""
["value"]=>
string(5) "Large"
["isSelected"]=>
bool(false)
["price"]=>
string(3) "$15"
}
}
["enableChoiceValue"]=>
bool(true)
}
But does not reflect that in the database or query string.