Skip to content

Instantly share code, notes, and snippets.

@softiconic
Last active December 2, 2023 18:59
Show Gist options
  • Save softiconic/1f0fdd3ad48e9aed9b28ae5f034cee1c to your computer and use it in GitHub Desktop.
Save softiconic/1f0fdd3ad48e9aed9b28ae5f034cee1c to your computer and use it in GitHub Desktop.
Show the weight and a message indicating the remaining weight on the WooCommerce cart and checkout.
add_filter( 'woocommerce_before_cart', 'display_total_weight_notice' );
add_filter( 'woocommerce_before_checkout_form', 'display_total_weight_notice' );
function display_total_weight_notice( $message ) {
// DEFINE the allowed weight limit
$allowed_weight = 3;
$cart_total_weight = WC()->cart->get_cart_contents_weight();
if( cart_total_weight <= $allowed_weight ) :
wc_print_notice( sprintf(
__( 'Your order has a total weight of %s. The remaining available weight is %s for the current shipping cost' ),
'<strong>' . wc_format_weight($cart_total_weight) . '</strong>',
'<strong>' . wc_format_weight($allowed_weight - $cart_total_weight) . '</strong>'
),'notice' );
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment