Support » Plugin: WooCommerce Pay for Payment » Not calculating custom fees

Viewing 15 replies - 1 through 15 (of 20 total)
  • To clarify a bit more, I have multiple custom fees dynamically added at checkout (based upon the presence of a particular item in the cart)using $woocommerce->cart->add_fee( __(‘fee_name’, ‘woocommerce’), amount ); which do not get included in the calculation of the % gateway fee. Otherwise a very useful plugin. Any ideas on how to fix this?

    Plugin Contributor podpirate


    I’m currently working on v1.2.1, where I am trying to address this issue.

    Thanks. The fix in 1.2.1 seemed to work but now with 1.2.3 calculations have gone very wrong, and I’m not even using taxes in the calculations, which others seem to be having problems with. The added fee is being calculated correctly, but the final order total is way off. So far I’ve been unable to locate where the extra amount is coming from.

    I take that back. It’s not calculating the added fee correctly either.

    Plugin Contributor podpirate


    Can give me an example?

    The site in question is

    I have multiple special cart fees set up, dependent upon whether certain products are added to the cart. Those function as intended on their own. I have also set up fees for 2 payment gateways using the pay for payment plugin, one at 4% and one at 6.5% Both are set to “No Taxes” with “Enable Extra Fees” and “Include Shipping” both activated.

    Here are some screenshots:
    Without gateway fee:

    With 4% gateway fee:

    With 6.5% gateway fee:

    As you can see, the gateway fees (the last fees before the final total) are overcalculated, and the Final Total is off by a wide margin.

    Still unable to determine where things are being thrown off.

    I have noticed if I change the cart contents to remove the special fees, the plugin calculates the gateway fes and cart totals correctly.

    Plugin Contributor podpirate


    With gets me a server not found. Is it (without the ‘s’)?

    Apologies for the typo. yes, it is without the ‘s’

    Plugin Contributor podpirate


    One big unsolved issue in the plugin is an inability to fetch the correct tax class and taxrate. Maybe this is connected to your problem.
    I’d need to take a look at your woocomerce tax options and tax rates. Knowing how you integrated the extra fees might help as well. Is it done by a plugin?

    Taxes have been disabled in this cart, so they dont come into play.

    Upon closer look, it appears the problem is that the custom fees are being added to the calculations twice. If you double the custom fees and add to the cart subtotal, then the gateway charge and order total are accurate.

    The fees are added with a theme function that looks for products in the cart:

    // add solar fees for all product installations
    add_action( 'woocommerce_before_calculate_totals', 'add_solar_fees' );
    function add_solar_fees() {
    	global $woocommerce;
    	$product_id_array = array( '982','983','984','985','986' );
    	$found = false;
    	//check if product already in cart
    	foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
    		if( in_array( $values['product_id'], $product_id_array ) ) {
    		$found = true;
    	// if product found, add fees
    	if ( $found ){
    	$woocommerce->cart->add_fee( __('Solar Installation Permit Fees', 'woocommerce'), 895 );
    	$woocommerce->cart->add_fee( __('Solar Engineering for Roof Mounting', 'woocommerce'), 965.25 );

    The gateway fee is being calculated as cart subtotal + (custom fees * 2)

    The order total is being calculated at subtotal + (custom fees * 3) + gateway fee

    Plugin Contributor podpirate


    Omygod, I think I got it…
    The plugin has to recalculatin fees twice. First time before the payment fee is added, in order to determine the cart total, second time after adding the payment fee, to get the carts total straight.

    Woocommerce’s WC_Cart->calculate_fees() function does not reset the fees total when calculating. Fees are simply summed up and up and up every time WC_Cart->calculate_fees() gets called. I think I’ll file a bug report to woocommerce…
    And shake my head. Three times!

    I’ll add a quick fix to my payment plugin, that simply sets the fee total to 0 before calculating it. It will be up soon.

    Thanks for your patience and cooperation!

    (P.S.: I created a test account in your shop like 2 hours ago, name “Jörn Lund”. You may delete it.)

    Sounds good. And thank you for working on it so fast.

    Looks like the fix corrected the order total, but the gateway fee is still doubling the custom fees.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Not calculating custom fees’ is closed to new replies.