如果订单少于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' );
}
}
问题是,如果客户体重没有超过1公斤(很多时候他们没有),并且继续结帐,那么结帐时通知就不清楚了.有什么建议可以防止这种情况发生吗?