There are cases when you sell by square meters that you need to offer discounts by quantity, more meters sold, more is the discount by meter.

We prefer to use formulas for this kind of calculations or a sequence of IF–THEN conditions, like in this demo.

But some users are asking for a grid where they can define their dimensions ranges and prices, so this is our approximation using CFO.

Take a look at our price grid sample (image on the right).

See comments in the next code example to better understand, remember that “//” symbols identify the line as a comment.
You can write your formula without comments of course.

// Here is our grid converted to an array, left key is the Height and right list of values are prices for each width column
// Prices with decimal values uses point, not comma, for example: "100.16" (remember this is PHP)
// Every row should have the same columns
$cfoGrid = array(
    "100" => "10|14|16|18|19",
    "125" => "12|15|17|20|21",
    "150" => "14|16|18|22|23",
    "175" => "16|17|19|24|25",
    "200" => "18|18|20|26|27",
    "225" => "20|19|21|28|29",
    "250" => "22|20|22|30|31",
    "300" => "24|21|23|32|33"

// Valid Heights, easily extracted from the prices grid
$validHeights = implode("|", array_keys($cfoGrid));

// Now we standardize the Height entered by customer
// If customer enters a value between ranges, it will be 
// rounded up to the next value in the list.
// Assuming {38V} is your input text box for height
$stdHeight = CFO_Sections({38V}, $validHeights);

// Defining valid Widths list
$validWidths = "100|125|150|175|195";

// And We standardize Width too, assuming {37V} is your 
// input text box for width
$stdWidth = CFO_Sections({37V}, $validWidths);

// Now let's obtain the crossing in the grid
// and get the list of prices for a given height (row)
$rowContent = $cfoGrid[$stdHeight];

// And finally asign the price to the product
// depending of the entered width (column)
$FinalPrice = CFO_Sections($stdWidth, $validWidths, $rowContent);

You can copy-paste this code, changing values in $cfoGrid and $validWidths it’s ready to run.
Of course, you should change the ids of your used options too.

You can visit this demo in our Demo Store