How to Add Custom Fees in WooCommerce Checkout (Conditionally with Code)

WooCommerce custom checkout fees setup with conditional logic using code

Want to add WooCommerce custom checkout fees based on conditions like location, payment method, cart total, or shipping class? You’re in the right place. This tutorial will walk you through the exact hooks, logic, and code to add dynamic fees to your checkout — without any plugins.

By the end, you’ll know how to add:

  • 💸 Payment gateway surcharge
  • 🚚 Delivery zone fee
  • 📦 Handling fee for heavy products
  • 🎯 Conditional fees by user role or cart value

Why Add Custom Fees in WooCommerce?

  • 📊 Pass payment processor costs to customers (like PayPal/Stripe fees)
  • 📍 Add fees based on shipping zone or delivery area
  • 🔐 Add security insurance, packaging, or carbon offset fees
  • 🧩 Enable or disable fees based on any business logic

WooCommerce Hook You’ll Use

The main hook for adding fees is:

add_action('woocommerce_cart_calculate_fees', 'your_function_name');

This fires during checkout right after totals are calculated. It’s powerful, flexible, and safe to use.


✅ Basic Example: Flat Custom Fee

add_action('woocommerce_cart_calculate_fees', 'add_flat_checkout_fee');
function add_flat_checkout_fee() {
 if (is_admin() && !defined('DOING_AJAX')) return;
 WC()->cart->add_fee('Handling Fee', 5.00, true); // true = taxable
}

This adds a $5 handling fee to all checkouts. Simple and clean.


🔁 Conditional Fee Based on Payment Gateway

Charge a surcharge if the user selects PayPal at checkout:

add_action('woocommerce_cart_calculate_fees', 'paypal_surcharge_fee');
function paypal_surcharge_fee() {
 if (is_admin() && !defined('DOING_AJAX')) return;
 if (WC()->session->get('chosen_payment_method') === 'paypal') {
 WC()->cart->add_fee('PayPal Surcharge', 2.50, true);
 }
}

Replace 'paypal' with your payment gateway ID.


🌍 Fee Based on Shipping Country

Apply an international handling fee for orders outside the US:

add_action('woocommerce_cart_calculate_fees', 'country_based_fee');
function country_based_fee() {
 if (is_admin() && !defined('DOING_AJAX')) return;
 $country = WC()->customer->get_shipping_country();
 if ($country !== 'US') {
 WC()->cart->add_fee('International Order Fee', 8.00);
 }
}

🛒 Fee Based on Cart Total

Add a small order fee for carts under $50:

add_action('woocommerce_cart_calculate_fees', 'small_order_fee');
function small_order_fee() {
 if (is_admin() && !defined('DOING_AJAX')) return;
 $cart_total = WC()->cart->get_subtotal();
 if ($cart_total < 50) {
 WC()->cart->add_fee('Small Order Fee', 3.50);
 }
}

🎯 Advanced: Fee Based on Product Category

Charge a packaging fee if the cart contains products in a specific category (e.g., "fragile"):

add_action('woocommerce_cart_calculate_fees', 'category_fee_fragile_items');
function category_fee_fragile_items() {
 if (is_admin() && !defined('DOING_AJAX')) return;
 $fragile_found = false;
 foreach (WC()->cart->get_cart_contents() as $item) {
 if (has_term('fragile', 'product_cat', $item['product_id'])) {
 $fragile_found = true;
 break;
 }
 }
 if ($fragile_found) {
 WC()->cart->add_fee('Fragile Item Packaging', 4.00);
 }
}

Make sure to replace fragile with your actual product category slug.


Final Thoughts

Adding custom WooCommerce checkout fees helps align your store with real-world business logic and profitability. Whether it’s payment surcharges, regional adjustments, or category-specific packaging — you can achieve it all using the woocommerce_cart_calculate_fees hook.

Need help building advanced WooCommerce logic for your store? Contact Babar Ilyas for hands-on development or store optimization.

Also check out our guide on customizing the WooCommerce checkout page for even more control over your customer experience.

FAQs: WooCommerce Custom Checkout Fees

Use the woocommerce_cart_calculate_fees hook in your theme’s functions.php file. It allows you to add custom fees based on cart conditions, payment methods, or shipping info.

The primary hook is woocommerce_cart_calculate_fees. It lets you calculate and apply dynamic fees during the cart/checkout process.

Yes. You can check the chosen payment gateway using WC()->session->get('chosen_payment_method') and apply a fee conditionally when PayPal or other gateways are selected.

Use the get_shipping_country() method from the customer object and apply your fee only if the shipping country matches your condition (e.g., not equal to US).

Absolutely. You can check the cart subtotal with WC()->cart->get_subtotal() and apply a small order fee if the amount is below your desired threshold.

Loop through the cart items and use has_term() to check for a specific product category. Then apply a fee using WC()->cart->add_fee() if a match is found.

Yes. When using add_fee(), set the third parameter to true to make the fee taxable, or false if it should not be taxed.

Yes. Any fee added with WC()->cart->add_fee() will appear on the cart, checkout, and order confirmation pages automatically.

You can’t directly remove fees once they are added in the same calculate_fees cycle, but you can use conditions to control when/if they’re applied to avoid adding them.

No. Everything can be done with clean PHP using WooCommerce’s native hooks. Plugins are only necessary if you want a UI for fee configuration.

Leave a Reply

Your email address will not be published. Required fields are marked *

    Branding Design Development Front-End Website-Redesigning Shopify-Development WordPress-Development
    Branding Design Development Front-End Website-Redesigning Shopify-Development WordPress-Development
    We love crafting unforgettable
    digital experiences, brands and websites with people like you.
    Follow us:
    Let’s get started
    We'd love to hear about your project.
    © 2025 babarilyas. All rights reserved.