Skip to content
Docs
Get RestroPress

Filter

rpress_get_cart_quantity

Updated
On this page

Filters the total quantity of the cart.

Runs in RPRESS_Cart::get_quantity(). The base value is the number of lines in the cart, not the sum of line quantities. The result is stored on the cart.

Parameters#

ParameterTypeDescription
$total_quantityintNumber of cart lines.
$arg2arrayThe cart contents.

Return value#

int. The cart quantity.

Example#

function my_cart_quantity( $total_quantity, $contents ) {
	$total = 0;
	foreach ( (array) $contents as $line ) {
		$total += isset( $line['quantity'] ) ? absint( $line['quantity'] ) : 1;
	}
	return $total;
}
add_filter( 'rpress_get_cart_quantity', 'my_cart_quantity', 10, 2 );

Notes#

The default counts lines, so a single line with quantity 3 is reported as 1 unless a callback changes it.

Source#

Applied in:

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

See also#

Was this page helpful?