Website Building » WooCommerce » How Do I Add a Custom Fee in WooCommerce?

How Do I Add a Custom Fee in WooCommerce?

Last updated on January 15, 2023 @ 1:42 pm

Adding a custom fee in WooCommerce is easy! You simply need to add a few lines of code to your functions.php file. Here’s how:

First, you’ll need to create a function to add the custom fee. You can name this function anything you want. For our example, we’ll name it “woo_add_custom_fee”.

PRO TIP: Adding a custom fee in WooCommerce is a great way to add an extra charge to your customers’ orders. However, it is important to note that this feature is only available in the WooCommerce plugin for WordPress, and not in the WooCommerce shopping cart itself. Therefore, if you are using the WooCommerce shopping cart on your site, you will need to install the WooCommerce plugin for WordPress and then follow the instructions below.

Next, you’ll need to add the following code to your function:

add_action( 'woocommerce_cart_calculate_fees','woo_add_custom_fee' );
function woo_add_custom_fee( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$percentage = 0.10; // Percentage of the cart total
$surcharge = $cart->cart_contents_total * $percentage;
$cart->add_fee( 'Custom Fee', $surcharge, true, '' ); // Add Custom Fee + taxable
}

//That's it! You have now successfully added a custom fee to your WooCommerce store!
Kathy McFarland

Kathy McFarland

Devops woman in trade, tech explorer and problem navigator.