How to add fees and discounts at the checkout in WooCommerce

Categorised: WordPress guides
Posted by aaron. Last updated: November 5, 2025

Here is a snippet of code to your child theme’s functions.php file or via a plugin that allows custom functions to be added. Do not add this custom code directly to your parent theme’s functions.php file as this will be removed when you update the theme.

Add a percentage based fee at the checkout to all transactions


add_action( 'woocommerce_cart_calculate_fees', 'toast_woocommerce_custom_fee' );
function toast_woocommerce_custom_fee() {
global $woocommerce;if (is_admin() && ! defined( 'DOING_AJAX' ) )
return;

$percentage = 0.05;
$fee = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Fee', $fee, true, '' );
}

Add a fixed fee at the checkout to all transactions


add_action( 'woocommerce_cart_calculate_fees', 'toast_woocommerce_custom_fee' );
function toast_woocommerce_custom_fee() {
global $woocommerce;if (is_admin() && ! defined( 'DOING_AJAX' ) )
return;

$fee = 5;
$woocommerce->cart->add_fee( 'Fee', $fee, true, '' );
}

Add a percentage discount at the checkout to all transactions


add_action( 'woocommerce_cart_calculate_fees', 'toast_woocommerce_custom_discount' );
function toast_woocommerce_custom_discount() {
global $woocommerce;if (is_admin() && ! defined( 'DOING_AJAX' ) )
return;

$percentage = 0.5;
$discount = -( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Discount', $discount, true, '');
}

Recent posts

June 3, 2026

Why Your WordPress Site Needs a Better Mobile Menu

A better mobile menu presents a better site experience all round. If you want to convert more visitors on mobile devices, you need to make sure you have a decent mobile menu.

Why-Does-Your-WordPress-Site-Needs-a-Better-Mobile-Menu
November 5, 2025

How to add fees and discounts at the checkout in WooCommerce

Here is a snippet of code to your child theme’s functions.php file or via a plugin that allows custom functions…

November 5, 2025

How to add a stylesheet to your WordPress login screen

How to add a stylesheet to your WordPress login screen Adding a stylesheet to your wp-login.php screen gives you a…