Hi @websitegirlca
Yes, you can add a service fee to the cart before tax by using a plugin or custom code. I’ll provide you with two options to achieve this:
Option 1: Using a plugin
One of the plugins that can help you achieve this is the “Extra Fees for WooCommerce” plugin. This plugin allows you to add various types of fees and discounts to your WooCommerce store, including percentage-based service fees. You can find more information about this plugin and how to set it up here: Extra Fees for WooCommerce.
Option 2: Using custom code
If you prefer using custom code, you can add the following code snippet to your theme’s functions.php file or a code snippet plugin. This code will apply a 20% service fee to the cart subtotal before tax calculation.
function custom_woocommerce_cart_calculate_fees( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
$service_fee_percentage = 20; // Set the service fee percentage
$cart_subtotal = $cart->get_subtotal();
$service_fee = ( $cart_subtotal * $service_fee_percentage ) / 100;
$cart->add_fee( __( 'Service Fee', 'woocommerce' ), $service_fee, false );
}
add_action( 'woocommerce_cart_calculate_fees', 'custom_woocommerce_cart_calculate_fees' );
Please note that modifying your theme’s files or using custom code may require some technical knowledge. If you’re not comfortable with this, I recommend reaching out to a developer or using the plugin option mentioned above.
I hope this helps!