Last active
February 9, 2024 19:17
-
-
Save mholubowski/3fafb1c3f017311eb61fc4c71464a058 to your computer and use it in GitHub Desktop.
Solid Affiliate - Commission Cap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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