Skip to content
Docs
Get RestroPress

Filter

rpress_can_purchase_fooditem

Updated
On this page

Filters whether a menu item can be purchased.

Runs in RPRESS_Fooditem::can_purchase(). The initial value is true unless the post status is not publish. The result is cast to bool. The check is used by the cart when contents are loaded and an item is added.

Parameters#

ParameterTypeDescription
$can_purchaseboolWhether the menu item can be purchased.
$fooditemRPRESS_FooditemThe menu item object.

Return value#

bool. True if the menu item can be purchased.

Example#

function my_can_purchase_fooditem( $can_purchase, $fooditem ) {
	// Block ordering menu item 123 outside business hours.
	if ( 123 === (int) $fooditem->ID && (int) wp_date( 'G' ) < 11 ) {
		return false;
	}
	return $can_purchase;
}
add_filter( 'rpress_can_purchase_fooditem', 'my_can_purchase_fooditem', 10, 2 );

Source#

Applied in:

  • includes/class-rpress-fooditem.php (line 627), in RPRESS_Fooditem::can_purchase()
Was this page helpful?