Skip to content

Instantly share code, notes, and snippets.

@mholubowski
Last active February 9, 2024 19:17
Show Gist options
  • Save mholubowski/3fafb1c3f017311eb61fc4c71464a058 to your computer and use it in GitHub Desktop.
Save mholubowski/3fafb1c3f017311eb61fc4c71464a058 to your computer and use it in GitHub Desktop.
Solid Affiliate - Commission Cap
/**
* Applies a maximum cap to the commission amount.
*
* @param float $total The calculated total commission for the order.
* @param \SolidAffiliate\Models\Affiliate $affiliate The affiliate object for whom the commission is calculated.
* @param \SolidAffiliate\Lib\VO\OrderDescription $order_description The order description object containing details about the order.
* @return float The possibly adjusted commission total, ensuring it does not exceed the maximum cap.
*/
function set_max_commission_cap(float $total, \SolidAffiliate\Models\Affiliate $affiliate, \SolidAffiliate\Lib\VO\OrderDescription $order_description): float {
// Set the maximum commission amount
$max_commission = 1000.0;
// Check if the calculated commission exceeds the maximum cap
if ($total > $max_commission) {
// If so, override the total with the maximum cap
$total = $max_commission;
}
// Return the possibly adjusted commission total
return $total;
}
add_filter('solid_affiliate/commission_calculator/commission_for_order', 'set_max_commission_cap', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment