WooCommerce is a powerful eCommerce platform. If you are using WooCommerce to build your online store then sometimes you may need to charge extra fees for specific services such as handling fees, gift wrapping fees, or Cash on Delivery (COD) fees. This post will lead you through the process of adding extra charges in WooCommerce using PHP, rather than plugins.
Experience lightning-fast speed, rock-solid security, and world-class support tailored for WordPress. Simply better hosting.
Adding Custom Fees Using WooCommerce Hooks
WooCommerce provides the woocommerce_cart_calculate_fees
hook, allowing developers to apply extra fees dynamically.
Steps to Add a Fixed Fee in WooCommerce
- Open your WordPress theme’s
functions.php
file. - Insert the following PHP snippet:
2 3 4 5 6 7 8 9 10 |
function tutorialswebsite_apply_custom_fee() { if (is_admin() && !defined('DOING_AJAX')) return; $fee_amount = 5; // Set additional charge amount WC()->cart->add_fee(__('Service Fee', 'woocommerce'), $fee_amount); } add_action('woocommerce_cart_calculate_fees', 'tutorialswebsite_apply_custom_fee'); |
- Save the file and check the checkout page for the additional fee.
Output: Please refer below screenshot

Also Read: Track and Display ‘Add to Cart’ Button Click Counts in WooCommerce
Adding Extra Charges for Cash on Delivery (COD)
If you want to apply an additional fee when customers select Cash on Delivery (COD), use this modified function:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
function tutorialswebsite_apply_cod_fee( $cart ) { if (is_admin() && !defined('DOING_AJAX')) return; if (isset(WC()->session)) { $chosen_payment = WC()->session->get('chosen_payment_method'); if ($chosen_payment === 'cod') { $fee_amount = 10; $cart->add_fee(__('COD Handling Fee', 'woocommerce'), $fee_amount); } } } add_action('woocommerce_cart_calculate_fees', 'tutorialswebsite_apply_cod_fee'); function refresh_checkout_on_payment_change() { ?> <script type="text/javascript"> jQuery(function($){ $(document.body).on('change', 'input[name="payment_method"]', function() { $('body').trigger('update_checkout'); }); }); </script> <?php } add_action('wp_footer', 'refresh_checkout_on_payment_change'); |
How It Works:
- Checks the selected payment method.
- If COD is selected, a
₹10
handling fee is applied. - The fee only appears when COD is chosen, keeping checkout fees dynamic.

Suggested Read: Partial COD (Cash on Delivery) in WooCommerce
Adding Additional Fees Based on Payment Method and Cart Total
You may need to charge fees differently based on the selected payment method and the cart total. The following snippet handles that:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
function tutorialswebsite_apply_payment_method_fees( $cart ) { if (is_admin() && !defined('DOING_AJAX')) return; $selected_payment = WC()->session->get('chosen_payment_method'); $cart_total = WC()->cart->cart_contents_total; if ($selected_payment === 'cod' && $cart_total < 250) { WC()->cart->add_fee(__('COD Fee (Orders Below 250)', 'woocommerce'), 10); } elseif ($selected_payment === 'paypal' && $cart_total > 300) { WC()->cart->add_fee(__('PayPal Processing Fee (Orders Above 300)', 'woocommerce'), 5); } } add_action('woocommerce_cart_calculate_fees', 'tutorialswebsite_apply_payment_method_fees'); function refresh_checkout_on_payment_change() { ?> <script type="text/javascript"> jQuery(function($){ $(document.body).on('change', 'input[name="payment_method"]', function() { $('body').trigger('update_checkout'); }); }); </script> <?php } add_action('wp_footer', 'refresh_checkout_on_payment_change'); |
How It Works:
- If COD is selected and the cart total is less than ₹250, a
₹10
fee is applied. - If PayPal is selected and the cart total exceeds ₹300, a
₹5
fee is added. - Ensures that fees are added dynamically based on cart conditions

Conclusion
Adding additional charges in WooCommerce can be done efficiently using PHP code or via a plugin. If you want more flexibility, coding offers dynamic control over when and how fees are applied. However, plugins provide a user-friendly way to manage extra costs without writing code.
Are you want to get implementation help, or modify or extend the functionality?
A Tutorialswebsite Expert can do it for you.
FAQs
You can use the woocommerce_cart_calculate_fees
hook to check if COD is selected and apply a handling fee dynamically. A sample PHP snippet for this is included in the guide above.
Yes, you can conditionally apply fees based on the selected payment method using PHP.
WooCommerce automatically recalculates fees when a user changes their payment method. Your PHP function should check the selected payment method dynamically to apply or remove fees accordingly.
Yes, you can apply fees conditionally based on cart total, such as adding a fee for orders below a specific amount or waiving it for higher-value purchases.
WooCommerce will include additional fees in the tax calculation if you enable the “taxable” option while adding fees programmatically.
Thanks for reading 🙏, I hope you found this tutorial helpful for your project. Keep learning! If you face any problems – I am here to solve your problems.

Pradeep Maurya is the Professional Web Developer & Designer and the Founder of “Tutorials website”. He lives in Delhi and loves to be a self-dependent person. As an owner, he is trying his best to improve this platform day by day. His passion, dedication and quick decision making ability to stand apart from others. He’s an avid blogger and writes on the publications like Dzone, e27.co