WooCommerce is a free open source ecommerce plugin for WordPress which allows anyone to easily set up an online store. WooCommerce has a wide-range of hooks and filters which allows the plugin to be easily customizable by the user for almost any theme. Currently, WooCommerce doesn’t allow users to add a handling charge to a checkout order from the dashboard, however, it does have an action that allows you to add a handling cost to the order total prior to the customer finalizing their purchase.
Adding a WooCommerce Handling Fee
This function will allow you to add a $5.00 handling charge to every order. The function will need to the placed in the body of your theme’s function.php file.
add_action( 'woocommerce_cart_calculate_fees','endo_handling_fee' ); function endo_handling_fee() { global $woocommerce; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $fee = 5.00; $woocommerce->cart->add_fee( 'Handling', $fee, true, 'standard' ); }
How it Works
The endo_handling_fee
is prompted whenever the woocommerce_cart_calculate_fees
action is fired. The data from the order is grabbed from the global variable $woocommerce
which will attach the handling fee. The amount and title of the fee is determined by using the add_fee
rule. You are able to set the fee type (in this case “Handling” and the amount to the checkout screen).
Customizing your Handling Fee
Now that the handling fee function has been added to the body of the function.php file you can easily adjust the fee type and amount to fit your needs. The example below will show an adjustment to the fee amount from $5.00 to $2.00 and the type from ‘Handing’ to ‘Processing’ by making simple changes to the $fee = $5.00;
and $woocommerce->cart->add_fee(‘Handling’ , $fee, true, ‘standard’);
lines of the function.
add_action( 'woocommerce_cart_calculate_fees','endo_handling_fee' ); function endo_handling_fee() { global $woocommerce; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $fee = 2.00; $woocommerce->cart->add_fee( 'Processing', $fee, true, 'standard' ); }
Now you know how to add a handling fee to your WooCommerce checkout page, customize the WooCommerce function to fit the fee type and amount you’d like to set for your customers, and have a better understanding of the overall function to explain the importance of the key elements that allow the function to work.