Skip to content
Docs
Get RestroPress

Filter

rpress_cart_contents

Updated
On this page

Filters the validated cart contents.

Runs in RPRESS_Cart::get_contents() after menu items that no longer exist or can no longer be purchased have been removed. The array is a re-indexed list of cart lines, each with keys such as id, quantity, options, instruction and addon_items. The filtered array becomes the cart's contents for that request.

Parameters#

ParameterTypeDescription
$cartarrayList of cart line arrays.

Return value#

array. The cart contents.

Example#

function my_cart_contents( $cart ) {
	return array_filter( $cart, function ( $line ) {
		return ! empty( $line['id'] );
	} );
}
add_filter( 'rpress_cart_contents', 'my_cart_contents', 10, 1 );

Notes#

Runs on every call to get_contents(), so keep callbacks fast. Changes are not written back to the session.

Source#

Applied in:

  • includes/cart/class-rpress-cart.php (line 183), in RPRESS_Cart::get_contents()

See also#

Was this page helpful?