Skip to content
Docs
Get RestroPress

Filter

rpress_fooditem_price

Updated
On this page

Filters the price of a menu item shown by rpress_price.

Runs in rpress_price after the menu item price has been adjusted for the tax settings and sanitized with rpress_sanitize_amount. RestroPress attaches rpress_format_amount at priority 10 and rpress_currency_filter at priority 20 to this hook, so a callback at a priority below 10 receives the plain numeric string and a later one receives the formatted text. The result is wrapped in a span and passed to rpress_fooditem_price_after_html.

Parameters#

ParameterTypeDescription
$pricestringSanitized price amount, later formatted by default callbacks.
$fooditem_idintID of the menu item.
$price_idint|falseVariable price ID, or false when not specified.

Return value#

string. The price.

Example#

function my_fooditem_price( $price, $fooditem_id, $price_id ) {
	$percent = (float) get_post_meta( $fooditem_id, '_my_display_discount', true );
	if ( $percent > 0 ) {
		$price = (string) round( (float) $price * ( 1 - $percent / 100 ), 2 );
	}
	return $price;
}
add_filter( 'rpress_fooditem_price', 'my_fooditem_price', 5, 3 );

Notes#

This only changes the displayed price. Cart totals are calculated elsewhere. Use priority 5 or lower to act before the default formatting callbacks.

Source#

Applied in:

  • includes/fooditem-functions.php (line 158), in rpress_price()

See also#

Was this page helpful?