Skip to content
  • Quick Ref
  • Contact
  • About
wpcanyon.com

wpcanyon.com

WooCommerce: Add a handling fee or surcharge

Posted on August 19, 2025 By Admin No Comments on WooCommerce: Add a handling fee or surcharge

WooCommerce: Add a Handling Fee or Surcharge

Adding a handling fee or surcharge to your WooCommerce store can help cover extra costs such as packaging, payment processing, or special delivery requirements. This tutorial shows you how to woocommerce add handling fee quickly and effectively using custom code snippets, ensuring the fee appears transparently during checkout.

Quick Fix: Add a Handling Fee in WooCommerce

  1. Access your WordPress theme’s functions.php file or use a site-specific plugin.
  2. Copy and paste the provided PHP code snippet to add a fixed or percentage-based handling fee.
  3. Save changes and test the checkout to confirm the fee appears correctly.

Why This Happens

WooCommerce by default does not include a handling fee option. Many store owners need to add extra charges to cover costs beyond product prices and shipping. Since WooCommerce’s built-in fees are flexible but require manual input, adding a custom handling fee via code automates this process and ensures consistent application.

Requirements

  • WooCommerce installed and active on your WordPress site.
  • Access to your theme’s functions.php file or a custom plugin for adding PHP code.
  • Basic familiarity with editing WordPress files or using a code snippet plugin.

Step-by-Step: Adding a Handling Fee in WooCommerce

1. Backup Your Site

Before making any code changes, always backup your site to avoid accidental loss or downtime.

2. Open Your Theme’s functions.php File

Use FTP, cPanel File Manager, or the WordPress theme editor to open functions.php located in your active theme folder.

3. Add the Handling Fee Code Snippet

Paste the following code at the end of the functions.php file. This example adds a fixed handling fee of $5.00 to every order:

add_action( 'woocommerce_cart_calculate_fees', 'add_handling_fee' );
function add_handling_fee() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $handling_fee = 5.00; // Fixed handling fee amount
    WC()->cart->add_fee( 'Handling Fee', $handling_fee, true, '' );
}

4. Save the File

Save your changes and upload the file back to the server if using FTP.

5. Test the Checkout

Add products to your cart and proceed to checkout. You should see the “Handling Fee” line item added to the order totals.

Optional: Percentage-Based Handling Fee

If you prefer a handling fee based on a percentage of the cart subtotal, use this code instead:

add_action( 'woocommerce_cart_calculate_fees', 'add_percentage_handling_fee' );
function add_percentage_handling_fee() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $percentage = 0.05; // 5% handling fee
    $cart_subtotal = WC()->cart->get_subtotal();
    $handling_fee = $cart_subtotal * $percentage;

    WC()->cart->add_fee( 'Handling Fee (5%)', $handling_fee, true, '' );
}

Common Pitfalls

  • Fee not showing: Ensure the code is placed in the active theme’s functions.php or a site-specific plugin, and WooCommerce is active.
  • Fee applied multiple times: The code checks for admin and AJAX contexts to prevent duplication. Avoid adding the snippet multiple times.
  • Tax settings: The third parameter in add_fee() controls if the fee is taxable. Set it to true or false depending on your tax rules.
  • Compatibility: Custom code may conflict with other plugins that modify cart fees. Test thoroughly.

Works On

Environment Compatibility
Web Servers Apache, Nginx, LiteSpeed
Hosting Panels cPanel, Plesk, DirectAdmin
WordPress Versions WooCommerce compatible versions (4.0+ recommended)

FAQ

Q1: Can I add different handling fees based on payment method?

Yes. You can check the chosen payment method using WC()->session->get('chosen_payment_method') inside the fee function and conditionally add fees.

Q2: How do I make the handling fee tax-exempt?

Set the third parameter of add_fee() to false. For example: WC()->cart->add_fee( 'Handling Fee', $fee, false );

Q3: Can I add handling fees only for specific products or categories?

Yes. Use WC()->cart->get_cart() to loop through cart items and conditionally apply fees based on product IDs or categories.

Q4: Will this handling fee appear in order emails and invoices?

Yes. WooCommerce includes fees in order totals, so the handling fee will appear in emails, invoices, and admin order details.

Q5: Is there a plugin alternative to adding handling fees?

Yes. Plugins like “WooCommerce Advanced Fees” or “WooCommerce Extra Fees Plugin” offer GUI-based fee management without coding.

WooCommerce How‑tos Tags:Checkout, Fees, Hooks, WooCommerce

Post navigation

Previous Post: Fix WordPress posts returning 404 (pages OK)
Next Post: Cloudflare cache rules for WordPress (no admin caching)

Leave a Reply Cancel reply

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

Recent Posts

  • Top WordPress Themes for Blogs in 2025
  • WordPress Admin Panel Trick: Adding ID Field to the Posts Listing
  • Solution previous_posts_link and next_posts_link Not Working
  • Show Top Commentators in WordPress Without a Plugin
  • How to Style Admin Comments in WordPress

Recent Comments

    Archives

    • August 2025

    Categories

    • Admin & Blocks
    • Admin & UI
    • Automation
    • Automation & Plugins
    • Comments
    • Comparisons
    • Database & Revisions
    • Developer Snippets
    • Fixes & Errors
    • Media & Thumbnails
    • Queries & Pagination
    • Security
    • Speed & Security
    • Tips & Tricks
    • WooCommerce How‑tos
    • WordPress Snippets
    • WordPress Themes
    • Terms & Conditions
    • Affiliate Disclosure

    Copyright © 2025 wpcanyon.com.

    Powered by PressBook WordPress theme

    Also by the maker of MySurveyReviews.com