WooCommerce: Display Total Weight @ Cart & Checkout
Following up from the other day’s snippet (deny checkout based on cart weight), you might want to show what is the current Total Weight on the cart and checkout page in case this is useful to your customers.
Of course, in order for this snippet to work, all your products must have a weight, otherwise the total will always be equal to 0. So here you go – enjoy!
PHP Snippet: Show Total Weight @ WooCommerce Cart & Checkout Pages
You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"
Does this snippet (still) work?
Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
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.
25 thoughts on “WooCommerce: Display Total Weight @ Cart & Checkout”
Great snippet. Only issue I have is that when the basket is shown, it shows the weight total on the right side summary as I need it. However, when I change a quantity, it appears as a notice on the top. Any way to keep the notice in the same place for this?
Yes, instead of wc_print_notice you’d echo a DIV instead. Also remove the “else” bit, you’re already in the cart
Thank you for the awesome snippet. Though it is working perfectly for me, there are times when it shows the fixed weight for the cart as 577.6kg. This has happened thrice in last 5 days. Any suggestions?
I have disable the snippet temporarily.
Uhm, no idea. My snippet uses a default WooCommerce function so nothing wrong in there. Could be a cache problem, or one of your products that has a weird weight?
I’m using this snippet but it shows the message twice, in the checkout page. What can the reason be?
Even if you switch theme temporarily?
I’m in a loophole because my staging site doesn’t have the problem, so it’s all right not to check with another theme. But on my production site if I install a new theme everything breaks.
I have left a post on WordPress forum: https://wordpress.org/support/topic/message-button-shown-twice-at-checkout/
I have found the culprit in a rich-snippet plugin. As soon as I deactivate that, your code works by showing the weight only once.
Now the problem is that I need that plugin, and it’s strange that it clashes with your short and simple code. Could you suggest something to resolve it?
Great to know your issue is solved. I’d suggest looking for a plugin alternative, if it breaks my simple snippet I’m sure it’s going to break even more WooCommerce functionalities. Either find a plugin alternative or get a developer to code the custom plugin for you. Hope this helps
Great snippet, so simple! Thanks a bunch for sharing 🙂
It still works great in WooCommerce 5.1, but only on cart and checkout pages. Is there a way to print the same notice in the mini cart too?
Hi Alex, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Shame this doesn’t seem to work with the new WooCommerce blocks
I don’t use blocks so not sure, sorry
Thanks for sharing this. Very useful. 2 questions please.
1. Is there are a way to stop auto scrolling to weight notice?
2. Can I deny checkout based on weight for all countries except UK?
Hi Gary, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Can you please share code to add total cart volume in cart page too? (HxWxL=Volume)?
I need something like: Total volume: xx m3.
Hi there, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Use in PHP 7.2+ script is slowly or my theme have problem.
I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?
To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.
Hope this helps!
Great snippet! Works with latest WC and PHP 7.1.
Do you know if it´s possible to show the weight of each item in cart?
Hey Alex – thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Could you help me how is it possible to add the total weight for the new order admin email? I have been trying to find out for 3 hours now, and can’t…
Thanks a lot,
Regina, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R