It’s official – there is no way to get the fees total from an order with a simple PHP getter (not sure why – you can get lots of values such as totals, addresses, dates, URLs with one line of code except for this basic thing!).
So, we’ve got to fix this. Let’s say you have access to the $order object (on the thank you page, in the WordPress dashboard, inside an order email, etc.); here’s a few lines of PHP you can use to calculate the total amount of order fees. Enjoy!
So, in order not to waste this post, you still find below the original way to calculate order total fees (by looping through all order fees and adding up totals), as well as the one liner that can help you save time. Enjoy!
PHP Snippet 1: Get Total Fees For an Order
* @snippet Get Fees Total @ WooCommerce Order
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 7
* @donate $9 https://businessbloomer.com/bloomer-armada/
This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101
WooCommerce: Add Checkout Fee for a Payment Gateway (e.g. PayPal) Here’s a simple PHP snippet to add a fee to the checkout for every payment or for a specific payment gateway. Please do remember that for certain payment gateways such as PayPal, adding checkout fees is currently against their Terms of Service so make sure to check this first. As usual, this needs to be […]
WooCommerce: Get Order Info (total, items, etc) From $order Object As a WooCommerce development freelancer, every day I repeat many coding operations that make me waste time. One of them is: “How to get ____ if I have the $order variable/object?“. For example, “How can I get the order total“? Or “How can I get the order items“? Or maybe the order dates, customer ID, […]
WooCommerce: Add Checkout Fees Based on Custom Radio Button This is a great WooCommerce snippet (or plugin, if you wish to call it like that) for those who want to provide conditional checkout fees. For example, you might need to display custom checkout radio buttons to pick premium packaging types, gift wrapping options, specific services or whatever can increase your AOV (Average Order Value). […]
WooCommerce: How to Add a Custom Checkout Field Let’s imagine you want to add a custom checkout field (and not an additional billing or shipping field) on the WooCommerce Checkout page. For example, it might be a customer licence number – this has got nothing to do with billing and nothing to do with shipping. Ideally, this custom field could show above the […]
WooCommerce: Create a Custom Order Status All WooCommerce orders go to either “processing”, “completed”, “on-hold” and other default order statuses based on the payment method and product type. Sometimes these statuses are not enough. For example, you might need to mark certain orders in a different way for tracking, filtering, exporting purposes. Or you might want to disable default emails by […]
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli