Price rules: is_under_offer, has_advertised_price, show_price_under_offer

Description

From Easy Property Listings 3.6, every price function asks the same small set of rules. Use them in templates and add-ons instead of reading the fields yourself, so your output always matches the rest of the site. Each rule has a filter, so you can change one decision without touching the others.

All of them are methods of the global $property object.


The rules

is_under_offer()

Is the listing under offer? True when it is marked under offer and is not sold.

Filter: epl_is_under_offer ($under_offer, $property)

has_advertised_price()

Does the listing advertise a price? True when Price Display is set to Yes, there is a price, and it is not an auction. Commercial listings count a lease price too. A listing showing the No Price (POA) label or an auction date advertises no price.

Filter: epl_listing_has_advertised_price ($advertised, $property)

show_price_under_offer()

Should under offer listings show their price? True only when Settings > Labels > Under Offer Price Display is set to Show the price (off by default from 3.6.1; on by default in 3.6). See Under Offer price display.

Filter: epl_show_price_under_offer ($show, $property)

get_under_offer_price( $price, $format )

The under offer price output. "Under Offer | $price" when the three rules above allow it, otherwise the Under Offer label on its own. $format is span (default), div, li or text (no HTML).

Filters: epl_under_offer_price_separator (default | ) and epl_get_under_offer_price ($output, $price, $format, $property)

get_poa_label( $fallback )

The No Price (POA) label from the settings. A label the user saved empty stays empty. $fallback is returned only when the setting has never been saved.


Examples

Add a class to under offer listings

global $property;
$class = $property->is_under_offer() ? 'my-card my-card--under-offer' : 'my-card';

Show a "Price guide" heading only when there is a price

global $property;
if ( $property->has_advertised_price() ) {
	echo '<h4>Price guide</h4>';
}

Hide the price under offer on rentals only

add_filter( 'epl_show_price_under_offer', function ( $show, $property ) {
	if ( 'rental' === $property->post_type ) {
		return false;
	}
	return $show;
}, 10, 2 );

Use a dash instead of a bar

add_filter( 'epl_under_offer_price_separator', function () {
	return ' – ';
} );

Related

Since 3.6.