Abstract
Sometimes you need that your formula calculates the final price in different ways given some conditions.
You can use conditionals in your formula although you are not a programmer!!!

Case of study
First identify what to ask to the customer in order to configure the purchase, let’s say we are asking for “Width” and “Height”.

Then idetify the limits of that variables, minumum and maximum values for that values:
Width min=1 and max=3
Height min=1 and max=50
That is very important point because if no limits are set, the customers could configure products that can be produced, so please pay attention when designing that limits.

Try to draw your formula in a paper to see how many conditions will be available to the customer.
Let’s say, for this example, we are going to add an extra cost of 10$ if one of the sizes are greater that 2.

Other condition will be, if square meters is greater than 10 we will apply a discount of 10% and if greater that 15, then 15% of discount over the base price per squaremeters.

Read about PHP Syntax
CFO use PHP syntax so you can use all Conditional Statements, take a look at PHP if…else…elseif Statements and PHP switch Statement

Example
Better to see it in action, so we have prepared a working demo in our demo store.

//
// Values entered by the customer in meters
$cuWidth = {12}; // Replace those options_id with yours
$cuHeight = {14};

//
// Calculate square meters
$SquareMeters = $cuWidth * $cuHeight;

//
// Check the limits
if($cuWidth<1 or $cuWidth>3) {
	//
	// Stop 1
	CFO_AbortFormula("Valid widths are from 1 to 3");
} elseif($cuHeight<1 or $cuHeight>50) {
	//
	// Stop 2
	CFO_AbortFormula("Valid heights are from 1 to 50");
} else {
	//
	// Ok, limits are in range here!
	// Now store price in a variable, so keep the original unchanged
	$OurPricePSQM = $Price; 

	//
	// Let's see the discounts
	if($SquareMeters>15) {
		//
		// Apply 15%
		$OurPricePSQM = $OurPricePSQM - ($OurPricePSQM *15/100);
	} elseif($SquareMeters>10) {
		//
		// Apply 10%
		$OurPricePSQM = $OurPricePSQM - ($OurPricePSQM *10/100);
	}
	
	//
	// Let's see that extra cost
	if($cuWidth>2 or $cuHeight>2) {
		$OurExtraCost = 10;
	} else {
		$OurExtraCost = 0;
	}

	//
	// And calculate final price
	$FinalPrice = ($SquareMeters * $OurPricePSQM ) + $OurExtraCost;
}

You can visit this demo in our Demo Store