Reordering Cart Totals in WooCommerce: Can It Be Done with Filters?

A recent discussion in the Business Bloomer Club Slack thread explored whether WooCommerce provides a straightforward way to rearrange cart and checkout totals. A client wanted the totals to appear in the following order: Subtotal, Fees, Shipping, Taxes, and finally the Total.

So, can this customization be achieved with a simple filter or hook, or does it require a deeper dive into WooCommerce’s templates?

Exploring Hooks and Filters

WooCommerce does offer many hooks, but as several members confirmed, cart-totals.php is hardcoded. The current order of Subtotal, Taxes, Shipping, and Fees is baked into the template, and without a specific filter to change the order, PHP modifications are limited.

CSS as a Workaround

Some members suggested rearranging elements using CSS as a quick workaround. While CSS won’t affect functionality, it can reorder the visual layout in both the cart and checkout. This approach isn’t ideal for everyone, especially if a more permanent and PHP-based solution is preferred.

Overriding Templates for Full Control

For developers who want complete control, overriding cart-totals.php can be a viable option. This involves creating a custom template file in your theme, which is an approach commonly used when WooCommerce doesn’t provide adequate filter flexibility. However, this requires ongoing maintenance, as template changes in WooCommerce updates could affect your customizations.

Suggesting a Solution to WooCommerce Core

In a class on contributing to WooCommerce Core, the idea of adding filter hooks for cart totals gained traction. This would provide developers a simple, flexible way to reorder totals in the cart and checkout without template overrides. If you’d like to see this feature in WooCommerce, consider submitting a pull request or supporting similar feature suggestions on GitHub!

Conclusion

For now, rearranging cart totals in WooCommerce may require a CSS solution or a custom template. But with enough community interest, perhaps a future WooCommerce release will include hooks for managing cart totals more easily. Keep an eye on WooCommerce’s GitHub repository if this is a feature you’d like to see!

Related content

Rodolfo Melogli

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

Reply

Your email address will not be published. Required fields are marked *