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
- Open your theme’s
functions.phpfile. - Add the code below.
- Save the file.
- 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'
);