How to Add a Small-Order Fee in WooCommerce Without a Plugin
Add a small fixed fee when a WooCommerce cart falls below your chosen subtotal, with a PHP snippet and clear guidance on coupons, taxes, and checkout.
Last updated:
Reviewed for accuracy by Jesse Nickles
Add the small-order fee
Back up your site and test the change on staging first. Add the following PHP to your active child theme's functions.php file, or a site-specific plugin if you prefer. HoverCraft users can follow the child theme instructions. Do not edit a parent theme, because an update can overwrite your changes.
add_action( 'woocommerce_cart_calculate_fees', function ( $cart ) {
if ( is_admin() && ! wp_doing_ajax() ) {
return;
}
$minimum = 50.00;
$fee = 5.00;
if ( $cart->get_subtotal() < $minimum ) {
$cart->add_fee( 'Small order fee', $fee, false );
}
} );
Replace 50.00 with your minimum item subtotal and 5.00 with the fee, both in your store's currency. This example adds a non-taxable fee when the items total less than 50 before coupons. An item subtotal of exactly 50 does not trigger the fee.
woocommerce_cart_calculate_fees is a WooCommerce action hook: it runs your PHP callback during cart fee calculations and passes in the cart object as $cart. The add_fee() method adds the charge to the calculated totals. WooCommerce recalculates fees as the cart changes, so you should add the fee in this hook rather than try to store it permanently. See the hook reference for its arguments and limitations.
Decide whether coupons count toward the minimum
The snippet checks get_subtotal(), which uses item prices before coupon discounts. For example, a cart with 55 in products and a 10 coupon does not incur the fee, even though the discounted items total 45.
If you want the fee to depend on the item amount after coupons, replace only the if line with:
if ( $cart->get_cart_contents_total() < $minimum ) {
Both checks exclude shipping and taxes. Do not use the grand total here. WooCommerce has not finished calculating it when this fee hook runs, and the final amount includes fees, shipping, and taxes.
Choose the fee's tax treatment
The final false in add_fee( 'Small order fee', $fee, false ) marks the fee as non-taxable. Set that argument to true only if the fee should be taxed under your store's applicable rules, and check the appropriate tax class. A fee name should also be unique among fees added during the same calculation. WooCommerce does not allow negative fee amounts, so use a proper discount mechanism when you need to reduce the price.
WooCommerce supports adding fees through this server-side hook for its Cart and Checkout blocks as well as classic cart and checkout flows. The visible layouts differ, so test the fee in the version your store actually uses. The WooCommerce Cart and Checkout blocks FAQ documents using this action for cart fees.
Test before going live
- Put items worth less than the threshold in the cart. Confirm that the fee appears once, with the expected label and amount.
- Raise the item subtotal to exactly the threshold and then above it. Confirm that the fee disappears.
- Apply a coupon that crosses the threshold. Check that the result matches your choice of pre-discount or post-discount subtotal.
- Check the cart and checkout, including mobile layout, shipping, tax calculation, and an update to the cart quantity.
If the fee does not appear, first confirm that the PHP is loading and that the subtotal is actually below your threshold. If it appears twice, check whether another snippet or fee extension adds a similar charge.