Home » WooCommerce: Display Total Weight @ Cart & Checkout

WooCommerce: Display Total Weight @ Cart & Checkout

by Tutor Aspire

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!

Show total product weight at WooCommerce Cart & Checkout

PHP Snippet: Show Total Weight @ WooCommerce Cart & Checkout Pages

/**
 * @snippet       Display Weight @ Cart & Checkout - WooCommerce
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WC 3.9
 * @donate $9     https://www.tutoraspire.com
 */
 
add_action( 'woocommerce_before_checkout_form', 'tutoraspire_print_cart_weight' );
add_action( 'woocommerce_before_cart', 'tutoraspire_print_cart_weight' );
 
function tutoraspire_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' );
   }
}

You may also like