Skip to content

[solid_affiliate/commission_calculator/commission_for_order] Customize commissions per-order. #1

@trey8611

Description

@trey8611

In this example, we set a max commission amount.

/**
* 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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions