Divide and round price by value of other element or field
-
Hello
I need to divide a per week rental price by the number of bedrooms in the property. (this will give me a per person per week price)
Number of bedrooms are imported from element {TotalBedrooms[1]}.
Using a code snippet from WPAllImport that allowed me to do another calculation on a previous import, I have created the following and would like to know if this will work, or if there’s a better way to do this.
PHP FUNCTION:
<?php function round_price( $price = null, $divider = {TotalBedrooms[1]}, $nearest = .10, $minus = 0 ) { if ( !empty( $price ) ) { // strip any extra characters from price $price = preg_replace("/[^0-9,.]/", "", $price); // perform calculations return ( round ( ( $price / $divider ) / $nearest ) * $nearest ) - $minus; } }
PRICE FIELD:
[round_price({WeeklyRent[1]},”{TotalBedrooms[1]}”,”10″,”.01″)]
Can anyone help with this?
Thank you
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Divide and round price by value of other element or field’ is closed to new replies.