Skip to content
Docs
Get RestroPress

Filter

rpress_payment_stats_item_earnings

Updated
On this page

Filters the running earnings total for a menu item while it is summed across payments.

Runs in RPRESS_Payment_Stats::get_earnings when computing earnings for a single menu item. It is applied inside the loop over matching cart items in each payment, after the item's price and item fees were added. The value is a running total across all payments processed so far, not a per-item amount.

Parameters#

ParameterTypeDescription
$earningsfloatRunning earnings total for the menu item.
$payment_idintID of the payment being processed.
$cart_keyint|stringKey of the item in the payment's cart details.
$itemarrayCart item details.

Return value#

float. The running earnings total.

Example#

function my_item_earnings( $earnings, $payment_id, $cart_key, $item ) {
	return $earnings - (float) get_post_meta( $payment_id, '_my_item_adjustment', true );
}
add_filter( 'rpress_payment_stats_item_earnings', 'my_item_earnings', 10, 4 );

Notes#

Because the value accumulates, an adjustment you subtract is applied once for every matching item.

Source#

Applied in:

  • includes/payments/class-payment-stats.php (line 196), in RPRESS_Payment_Stats::get_earnings()

See also#

Was this page helpful?