How to Use a Custom Formula to Calculate the Donation Fee

TL;DR
Donation Platform for WooCommerce calculates donation fees using this default formula:
[Total fee] = [Fixed fee] + ([Variable fee] * [Transaction amount])
To override this, use the wcdp_fee_amount filter to apply your own logic.

Default Fee Calculation

By default, the Donation Platform for WooCommerce uses the following formula to estimate the donation fee for fee recovery:

Total fee = Fixed fee + (Variable fee × Transaction amount)

This ensures the donor covers the payment processor’s fees so your cause receives the full intended donation.

Customizing the Fee Calculation

If you need to use a different formula (e.g., to reverse-calculate the gross amount needed to receive a net donation), you can hook into the plugin using the wcdp_fee_amount filter.

Filter Hook

apply_filters( 'wcdp_fee_amount', $fee, $payment_method, $cart );
  • $fee — The calculated fee (float)
  • $payment_method — The chosen payment method (string)
  • $cart — The WooCommerce cart object

Example: Reverse Calculation

To calculate the total donation amount needed so that you receive the original amount after fees, you can use this formula:

Total amount = (Transaction amount + [Fixed fee]) / (1 - [Variable fee])

PHP Example

Here’s how to implement that assuming a fixed fee of 0.25 and a variable fee of 1.5% (0.015):

add_filter( 'wcdp_fee_amount', function( $fee, $payment_method, $cart ) {
    $transaction_amount = $cart->get_subtotal(); // donation subtotal before fees

    $fixed_fee = 0.25;
    $variable_fee = 0.015; // 1.5%

    // Calculate the fee needed so the net amount equals the original
    $gross_amount = ( $transaction_amount + $fixed_fee ) / ( 1 - $variable_fee );
    $fee = $gross_amount - $transaction_amount;

    return round( $fee, 2 ); // round to two decimal places
}, 10, 3 );

This method ensures that the donor pays enough to cover both the fixed and percentage-based fees, and the intended donation amount reaches you in full.

Notes

  • This filter works on the cart-level subtotal (excluding tax and shipping).
  • You can conditionally modify the logic based on the payment method if needed.
  • Always validate your custom fee formula in a staging environment before using it in production.