Skip to content
GPLWP Guides

How to add conditional fees in WooCommerce

WooCommerce Time About 30 minutes 6 steps Updated 21 Sep 2026

WOOCOMMERCE
The short answer

WooCommerce does not provide an admin screen for conditional fees. For one simple rule, add a PHP snippet using WooCommerce’s cart fee hook; for multiple rules based on products, customers, locations, shipping or time, use a fee rules plugin.

The route
  1. 01Define the fee rule
  2. 02Choose the manual route
  3. 03Add one simple fee
  4. 04Account for checkout conditions
  5. 05Test totals before launch
  6. 06Use a rules plugin for speed

What you need

  • A WooCommerce store with products and checkout configured
  • Administrator access or a safe way to add PHP snippets
  • A staging site or backup before changing checkout code
  • A clear fee rule, such as a fixed charge for small orders

Define the fee rule

Write down exactly when the fee applies, how much it costs, whether it is taxable, and what customers should see at checkout. For example: add a £3 handling fee when the cart subtotal is below £50, but do not add it when a free-shipping coupon is active.

Decide whether the rule uses the subtotal, shipping-inclusive total, product quantity, selected payment method, customer location or shipping method. Ambiguous rules are where duplicate charges and unexpected fees usually start.

Choose the manual route

For one or two straightforward conditions, custom code is a reasonable option. WooCommerce recalculates cart fees during totals calculation, so the normal approach is to attach a callback to woocommerce_cart_calculate_fees and add the fee with the cart’s fee method. Fees are not persistent cart items and must be added again whenever totals are recalculated.

The drawback is maintenance. You must handle tax status, coupons, logged-in users, checkout refreshes, payment methods and future WooCommerce changes yourself. Do not put the code directly in a parent theme’s functions.php, because a theme update can remove it; use a child theme or a snippets plugin instead.

Add one simple fee

For a basic fixed fee, add a snippet through your child theme or a code-snippet tool. This example adds a £3 fee when the cart subtotal is below £50:

add_action( 'woocommerce_cart_calculate_fees', function( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { return; } if ( $cart->get_subtotal() < 50 ) { $cart->add_fee( 'Small order handling', 3, false ); } } );

Change the label, threshold and amount to suit your rule. Add further checks inside the condition when needed, but avoid adding the same fee from more than one callback. WooCommerce’s documented fee API supports fixed and percentage-style calculations, and the fee can be marked taxable when appropriate.

Account for checkout conditions

Payment-method fees need the selected gateway from the WooCommerce session, while location rules should read the customer’s billing or shipping address. These values can change during checkout, so the fee must be recalculated after the customer updates the form. WooCommerce specifically documents server-side fee calculation for selected payment methods using the cart fee hook.

Be careful with subscriptions: fees added through the cart calculation hook can apply to recurring carts unless you deliberately restrict them. Also check whether your store uses the Cart and Checkout blocks. Some shortcode hooks do not work in the block experience, and an incompatible extension may require switching back to the classic checkout.

Test totals before launch

Test the cart, classic checkout and block checkout if your store uses both. Check the fee with the condition met and not met, then test coupons, shipping changes, guest customers, logged-in customers, tax display, refunds and the order confirmation email.

Look for the most common failure: the fee appears twice after an AJAX checkout refresh. That normally means the callback is registered twice or another plugin is adding the same fee. Also confirm that a percentage fee is calculated from the intended base and that subscription fees are not being charged again by mistake.

Use a rules plugin for speed

If you need several conditions, the faster route is a rule-based fee plugin rather than maintaining custom PHP. WPC Smart Fees for WooCommerce is a suitable option when you need fixed or percentage fees based on cart values, products, customers, locations, coupons, shipping methods or time windows. It also provides taxable-fee settings, notices, fee-stacking controls and rule import/export.

Create a rule, choose whether the amount is fixed or percentage-based, set the conditions, enter the customer-facing label, choose the tax treatment, then save. Recreate the examples from your manual plan and test each rule independently before enabling several rules together. Check the plugin’s current Cart and Checkout block compatibility before using it on a block-based checkout, because WooCommerce advises checking extension compatibility for the block experience.

The fast route

Let WPC Smart Fees for WooCommerce do it

Rule-based fixed or percentage fees by cart, customer, location, shipping, and time; choose it for flexible checkout surcharges.

Get WPC Smart Fees for WooCommerce

Sources

  1. woocommerce.com /document/subscriptions/develop/recurring-cart-fees/?utm_sou…
  2. woocommerce.com /document/add-a-surcharge-to-cart-and-checkout-uses-fees-api…
  3. developer.woocommerce.com /docs/block-development/getting-started/faq/?utm_source=open…
  4. woocommerce.com /document/woocommerce-store-editing/customizing-cart-and-che…

Questions

Does WooCommerce have conditional fees built in?
No. WooCommerce provides the fee API and the <code>woocommerce_cart_calculate_fees</code> hook, but it does not include a general-purpose settings screen for building conditional fee rules. You can write PHP for a small number of conditions, or install a plugin when rules depend on products, customers, locations, shipping methods, coupons or time periods.
Where should I add custom fee code?
Add custom fee code to a child theme or a snippets plugin, not directly to the parent theme’s <code>functions.php</code>. Parent-theme updates can overwrite the file. Use a staging site or backup first, and make sure the callback runs only once so checkout refreshes do not create duplicate fee lines.
Can I charge a fee based on the payment method?
Yes. Read the selected payment method from the WooCommerce session inside the cart-fee calculation callback, then add the fee only when its gateway identifier matches. The value may not be available until the customer selects a gateway, so checkout must recalculate totals when the selection changes. WooCommerce documents this as a server-side fee calculation pattern.
Why does my conditional fee appear twice?
A duplicated fee usually means the rule is being added by two callbacks, the snippet was registered twice, or a plugin and custom code implement the same condition. It can also happen when code adds a new fee without letting WooCommerce recalculate the previous result. Search active snippets and plugins for the fee label, then test with only one implementation enabled.
Will conditional fees work with the WooCommerce Checkout block?
They can, but compatibility depends on the code or extension. WooCommerce says some shortcode hooks do not work in the block checkout and recommends checking each extension’s compatibility. If a fee plugin does not support the block experience, switch to the classic checkout or choose an updated extension that declares block compatibility.