How Do I Add a Custom Fee at WooCommerce Checkout?
How to Add a Fee With the WooCommerce Fees API
The woocommerce_cart_calculate_fees action runs during cart/checkout total calculation, and calling WC()->cart->add_fee() within it adds a named fee line to the order total, displayed clearly alongside the subtotal, shipping, and tax.
add_action( 'woocommerce_cart_calculate_fees', function( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
$cart->add_fee( __( 'Handling Fee', 'textdomain' ), 4.99 );
} );
Things Worth Getting Right
- The admin/AJAX check shown above is important — without it, the fee can be added incorrectly in admin-side calculations, causing confusing discrepancies.
- Percentage-based fees are calculated the same way, just computing the amount from
$cart->get_subtotal()or the full cart total rather than using a fixed number. - Conditional fees (only for orders below a minimum, or only for a specific payment method) need additional logic within the same hook to check the relevant condition before calling
add_fee(). - Tax handling on the fee itself needs deciding —
add_fee()accepts a taxable parameter, and getting this wrong can cause the fee to be taxed (or not) incorrectly relative to the store's actual tax obligations. - Displaying the reason for the fee clearly to customers (a well-chosen fee name, or accompanying text) avoids confusion and support questions about an unexpected line item.
Implementing the Fee Properly
- Use the
woocommerce_cart_calculate_feeshook with the admin/AJAX guard included. - Decide the fee's tax treatment correctly for the store's specific tax obligations.
- Test with different cart combinations, including any conditional logic, to confirm the fee applies exactly when intended.
Need a custom or conditional fee built and tested properly? See custom WooCommerce development.