When adding multiple fees to the checkout in woocommerce, is it possible to prioritise the order of them? Currently it looks like woocommerce orders them by the fee value, so for example: Fee 1 = £10.00, Fee 2 = £20.00, they would get ordered like so:
- Subtotal
- Fee 2 = £20.00
- Fee 1 = £10.00
- Total
Is it possible to have a custom order at all? Maybe adding a priority to the action the fee is attached to? I would like Fee 2
to always be the last fee item.
Is this achievable?
In Woocommerce Fees are handled by the
WC_Cart_Fee
class and if you look to the source code ofget_fees()
method, you will see that sorting is made by fee amount insort_fees_callback()
withuasort()
php sorting function.1) Sorting Fees by name: First here is a custom function to sort fees by their label name:
Code goes in function.php file of your active child theme (or active theme). Tested and works.
2) Display - Overriding the templates
cart/cart-totals.php
andcheckout/review-order.php
.In both templates files you will replace the line:
by
Related: Sort fees by name on WooCommerce Orders and email notifications