I am using the following code to add a notice on the cart page if the order has less than 1kg.
// Add notice on cart when order is less than 1kg
add_action('woocommerce_check_cart_items','check_cart_minweight');
function check_cart_minweight(){
global $woocommerce;
$minweight = $woocommerce->cart->cart_contents_weight;
if( $minweight < 1 ){
wc_add_notice( sprintf( __( 'You have selected %sKg, add more items, orders over 1kg get free shipping', 'woocommerce' ), $minweight ), 'success' );
}
}
The problem is that if the customer does not get over 1kg (many times they do not) and proceeds to checkout, the notice does not clear on checkout. Any advice to prevent this?