WordPress.org

Calculated Fields Form[resolved] simple discount formula and exemption (2 posts)

1. dirtmcgirt
Member
Posted 2 years ago #

Hello,
I have been at this for days:(
I have 3 fields:
fieldname10 = 35
fieldname9 = 65

fieldname8 has 7 checkboxes,
check any 1 box and value = 65,
2 checkboxes = 125
3 checkboxes = 180 etc.
So there is a discount for the more boxes checked in this field only.
The following formula works to accomplish this, but checking fieldname9 and 10 will only show up in the total IF i have already checked at lest one box in fieldname8. In other words, if someone wants to only check fieldname9 and nothing else, there is no returned value in the totals box. i need fieldname9 and 10 to be independent of the formula but added to the total when checked.

my formula:

(function(){
var v;
switch(fieldname8){
case 65:
v = 65;
break;
case 130:
v = 125;
break;
case 195:
v = 180;
break;
case 260:
v = 230;
break;
case 325:
v = 265;
break;
case 390:
v = 310;
break;
case 455:
v = 340;
break;
}
return v + fieldname9 + fieldname10;
})();

2. codepeople
Member
Plugin Author

Posted 2 years ago #

Hi,

In this case you only should define an initial value for the varaible "v", like follow:

(function(){
var v = 0;
switch(fieldname8){
case 65:
v = 65;
break;
case 130:
v = 125;
break;
case 195:
v = 180;
break;
case 260:
v = 230;
break;
case 325:
v = 265;
break;
case 390:
v = 310;
break;
case 455:
v = 340;
break;
}
return v + fieldname9 + fieldname10;
})();

Best regards.

This topic has been closed to new replies.