autora lab

Developer hooks

Product Revenue Share has one filter to change an earning and four actions that run as earnings move from sale to payout. Use them to adjust shares in code, or to send payouts to your accounting tool.

Add these snippets to a small custom plugin or to your child theme's functions.php.

Change an earning: prs_earning_amount

Runs for each payee on each order line, before the earning is saved.

  • float $amount: the calculated earning.
  • array $assignment: the payee row, with payee_id, type (percent or fixed) and value.
  • WC_Order_Item_Product $item: the order line.

Return the new amount, or 0 to skip the earning. This example limits any single earning to 50:

add_filter( 'prs_earning_amount', function ( $amount, $assignment, $item ) {
	return min( $amount, 50 );
}, 10, 3 );

Actions

Action and argumentsRuns
prs_earning_created
int $order_id, WC_Order_Item_Product $item, array $row
For each earning recorded from an order line. $row holds payee_id, rate_type, rate_value and amount.
prs_earning_cleared
int $cleared
After the daily job moves earnings to Ready to pay, with how many it moved.
prs_earning_reversed
int $order_item_id, float $ratio
After a refund reduces the earnings on an order line. $ratio is the refunded share, from 0 to 1.
prs_payout_created
int $payout_id, int $payee_id, float $amount
After you mark a payout as paid.

This example writes every payout to the PHP error log:

add_action( 'prs_payout_created', function ( $payout_id, $payee_id, $amount ) {
	$payee = get_userdata( $payee_id );
	error_log( sprintf( 'Payout %d: %s to %s', $payout_id, $amount, $payee ? $payee->user_email : $payee_id ) );
}, 10, 3 );

The daily job

Earnings move from On hold to Ready to pay in a daily Action Scheduler job called prs_clear_earnings, in the product-revenue-share group. You can see its runs under Tools > Scheduled Actions. If it misses a day, nothing is paid too early, because marking a payout as paid checks the dates again.