Skip to main content
Login Join
Snippet · PHP

Add a Custom Fee to WooCommerce Checkout

Shared by Amit Dholiya · August 19, 2026 · @woocommerce_cart_calculate_fees

9 views
Back to Snippets

You can automatically add a small handling or service fee to the WooCommerce cart and checkout. This is useful for processing fees, packaging charges, or service charges.

Steps

  1. Open your theme’s functions.php file.
  2. Add the code below.
  3. Save the file.
  4. Add a product to your cart and proceed to checkout.

Done — a custom fee will be added automatically to the order total.

function add_custom_checkout_fee() {

    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
        return;
    }

    if ( ! WC()->cart ) {
        return;
    }

    $fee = 5;

    WC()->cart->add_fee(
        'Handling Fee',
        $fee,
        false
    );
}

add_action(
    'woocommerce_cart_calculate_fees',
    'add_custom_checkout_fee'
);
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments