Filter
rpress_get_cart_quantity
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#
| Parameter | Type | Description |
|---|---|---|
$total_quantity | int | Number of cart lines. |
$arg2 | array | The 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), inRPRESS_Cart::get_quantity()
See also#
Was this page helpful?
