We're using an API to display a list of properties in search results and we need to apply a fixed minimum price of £300 for short stays at properties.
Currently, it is possible to input a stay of 1 or 2 nights and for the price for a particular property to display less than £300.
We need (I presume) an if statement to display £300 in these scenarios.
The below is what we have in place to set the price...
<?php echo money_format('£%i', $property_price / ( $nights )) ?>
Variables are based on attributes from the API.
Please could anyone advise how we can convert this to include something similar to 'display £300 if price returned is less than this amount'?
The suggested edit of the title is incorrect. I don't want to display the right price (?) - that's why I didn't say that... I want to display a fixed price of £300 even if the results from the API return a price less than this amount.
The answer comes from a long chat talk with the author and a careful reading of what he was trying to do.
Answer I see that there is something wrong in your code. This is right:
<?php if ($property_price < 300) $property_price = 300; ?>
<?php echo money_format('£%i', $property_price / ( $nights )) ?>
(that of course is equivalent to a max...)
Just use the max function:
<?php echo money_format('£%i', max(300, $property_price / ( $nights ))) ?>