woocommerce_cart_calculate_fees

WooCommerce runs this action while calculating cart fees, allowing code to add a fee using the cart object before the final totals are produced.

Quick Reference

TypeAction hook
AreaCart fees
Arguments$cart (WC_Cart)
SourceWooCommerce code reference

How It Works

A callback receives the current WC_Cart instance and can call $cart->add_fee(). Fees are recalculated with the cart, so add them through this action rather than storing a one-time total. The add_fee() method accepts a label, amount, taxable flag, and optional tax class.

PHP Example

add_action( 'woocommerce_cart_calculate_fees', function ( $cart ) {
    if ( is_admin() && ! wp_doing_ajax() ) {
        return;
    }

    if ( $cart->get_subtotal() < 50 ) {
        $cart->add_fee( 'Small order fee', 5 );
    }
} );

This adds a non-taxable fee of five units of the store's currency when the pre-discount cart subtotal is below 50. Adapt thresholds and tax treatment to your store.

Add the code to a site-specific plugin or a child theme's functions.php file, then test it on a staging site.

Common Pitfalls

The example uses get_subtotal(), which checks item prices before coupons are applied. A coupon that lowers the amount payable below 50 will not, by itself, activate this fee. Choose the amount you test according to whether your rule concerns the original item subtotal or what the customer will actually pay.

Each fee needs a unique name within the cart calculation, and WooCommerce's add_fee() method does not accept a negative amount. Use a coupon or an appropriate discount mechanism to reduce prices, rather than creating a negative fee. The example's fee is non-taxable because the optional $taxable argument is omitted.

Compatibility

This hook runs in WooCommerce's cart totals logic, including when the cart or checkout needs recalculation. Test the behavior with your payment and shipping setup.