Title: IF Statement
Last modified: August 6, 2018

---

# IF Statement

 *  Resolved [namazee](https://wordpress.org/support/users/namazee/)
 * (@namazee)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/if-statement-12/)
 * Based on this form, i would like to get some advice from you,
 * If the volumetric weight is higher than the actual weight, i would like to use
   the volumetric weight for my calculation,
 * if the actual weight is higher than the volumetric weight, then i want to use
   the actual weight for my calculation..
 * Is that possible?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fif-statement-12%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/if-statement-12/#post-10563877)
 * Hello [@namazee](https://wordpress.org/support/users/namazee/),
 * You simply should use the “MAX” operation. I’ll try to describe the process with
   an example, assuming that there are two fields: fieldname1 for volumetric weight
   and fieldname2 for actual weight, the equation would be:
 *     ```
       MAX(fieldname1,fieldname2)
       ```
   
 * Best regards.
 *  Thread Starter [namazee](https://wordpress.org/support/users/namazee/)
 * (@namazee)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/if-statement-12/#post-10563933)
 * i used it but it doesn’t seems to detect the MAX
 * (function(){
    MAX(fieldname32,fieldname28);
 * if(fieldname32 <= 3) return 51.00;
    if(fieldname32 > 3) return 51.00 +(fieldname32-
   3) *16;
 * })();
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/if-statement-12/#post-10564591)
 * Hello [@namazee](https://wordpress.org/support/users/namazee/),
 * I’m sorry, but that equation has no sense. You should assign the value returned
   by the MAX operation to a variable, and then, use this variable in the conditional
   statements and mathematical operations, as follows:
 *     ```
       (function(){
       var m = MAX(fieldname32,fieldname28);
       if(m <= 3) return 51.00;
       return 51.00+(m-3)*16;
       })();
       ```
   
 * Best regards.
 *  [sitisarahothman](https://wordpress.org/support/users/sitisarahothman/)
 * (@sitisarahothman)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/if-statement-12/#post-10605362)
 * why this code doesnt function in my calculation ?
 * (function(){
 * if(fieldname4==1){
 *  if(fieldname5==”sponge”){
 *  if(fieldname2>=0.8 || fieldname2<1.1)
    fieldname1=75.00; else if(fieldname2>
   =1.1 || fieldname2<1.5) fieldname1=85.00; else if(fieldname2>=1.5 || fieldname2
   <1.8) fieldname1=95.00; else if(fieldname2>=1.8 || fieldname2<2.2) fieldname1
   =110.00*quantity; else if(fieldname2>=2.2 || fieldname2<2.5) fieldname1=130.00;
   else if(fieldname2>=2.5 || fieldname2<3.0) fieldname1=160.00; }
 *  else
    { if(fieldname2>=0.8 || fieldname2<1.1) fieldname1=95.00; else if(fieldname2
   >=1.1 || fieldname2<1.5) fieldname1=110.00; else if(fieldname2>=1.5 || fieldname2
   <1.8) fieldname1=125.00; else if(fieldname2>=1.8 || fieldname2<2.2) fieldname1
   =145.00; else if(fieldname2>=2.2 || fieldname2<2.5) fieldname1=170.00; else if(
   fieldname2>=2.5 || fieldname2<3.0) fieldname1=205.00*quantity; } }
 *  else if(fieldname4==2)
 *  if(fieldname5==”sponge”))
    fieldname1=170.00; else fieldname5=220.00;
 *  else
 *  if(fieldname==”sponge”)
    fieldname1=295.00; else fieldname1=390;
 *  return fieldname1;
 * })();
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/if-statement-12/#post-10605835)
 * Hello [@sitisarahothman](https://wordpress.org/support/users/sitisarahothman/),
 * There are multiple issues in your equation:
 * – First in this piece of code the field’s name is wrong: `if (fieldname == "sponge")`
   the fields’ names have the structure: fieldname#
 * – Second, the plugin replaces all texts with the structure: fieldname# with the
   corresponding field’s value, so, all pieces of code with the format: `fieldname1
   =#;` (like fieldname1 = 75.00; fieldname1 = 85.00; fieldname1 = 95.00; ….) are
   invalid, because you cannot assign a number to a number.
 * – Third, you are using a variable in the equation called: quantity, that is not
   being defined at least in the equation.
 * – Fourth, there are nested condition statements (“if”) that are ambiguos, in 
   this cases you should use the symbols {} to solve the ambiguity and delimit the
   code that corresponds to each of them.
 * Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘IF Statement’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/if-statement-12/#post-10605835)
 * Status: resolved