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
/**
* @snippet Display Weight @ Cart & Checkout - WooCommerce
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WC 3.9
* @community https://businessbloomer.com/club/
*/
add_action( 'woocommerce_before_checkout_form', 'bbloomer_print_cart_weight' );
add_action( 'woocommerce_before_cart', 'bbloomer_print_cart_weight' );
function bbloomer_print_cart_weight() {
$notice = 'Your cart weight is: ' . WC()->cart->get_cart_contents_weight() . get_option( 'woocommerce_weight_unit' );
if ( is_cart() ) {
wc_print_notice( $notice, 'notice' );
} else {
wc_add_notice( $notice, 'notice' );
}
}
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 π
Nice!
Hi Rodolfo,
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
Hi Rodolfo,
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?
Many thanks,
Gary
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
Dear Rodolfo,
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
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