Overview – adding a custom fee to woocommerce checkout
I was hired to add a custom fee to a WooCommerce checkout when certain conditions were met.
The site roofrazor.com sells tools to remove snow from a roof. These innovative products allow customers from northern latitudes in the US and Canada to remove snow from their roof before it becomes a hazard to people walking below the eaves of the roof.
It has a wholesale side to it’s business and as part of that they allow their dealers to drop ship product to their end users.
The dropping shipping process has a custom handling fee of $4.00 to package and send off the products.
I added some custom code that checks the woocommerce_cart_calculate_fees action hook. If the user has the role dealer and they “do you want to drop ship” check box is checked then the fee is added to the cart.
The customer comes to the site, and logs in as a wholesale user, they have been allocated the user role “wcwp_dealer”.
If the user is a wholesale user a new checkbox is presented at the top the checkout page to select if this is a drop shipping order, if that is checked my code kicks in and a custom handling fee of $4.00 is added to the order.
One of the challenges of this code is to ensure the fees are added to the cart if a customer refreshed the checkout page without the correct hook being called the code was disappearing on checkout page reload.
Video
Here’s a walk through vide to show how the process works.
Wrap up
If you need help adding custom fees to your WooCommerce store then why not get in touch by visiting my work with me page.
Photo by Markus Spiske on Unsplash