在 woocommerce 订单中设置最大重量
Set max weight in woocommerce orders
我正在尝试为我使用 woocommerce 构建的网店中的每个订单设置最大重量限制。假设我想为每个订单设置 30 公斤的限制。我尝试在标准的 woocommerce 运输设置中这样做。我也尝试了一些不同的插件,但这些都是为了设置不同的价格限制。
有没有人以前做过这个,你用的是什么插件?
这是您要找的吗?
add_action('woocommerce_check_cart_items','check_cart_weight');
function check_cart_weight(){
global $woocommerce;
$weight = $woocommerce->cart->cart_contents_weight;
if( $weight > 30 ){
wc_add_notice( sprintf( __( 'You have %sKg weight and we allow only 30Kg of weight per order.', 'woocommerce' ), $weight ), 'error' );
}
}
我正在尝试为我使用 woocommerce 构建的网店中的每个订单设置最大重量限制。假设我想为每个订单设置 30 公斤的限制。我尝试在标准的 woocommerce 运输设置中这样做。我也尝试了一些不同的插件,但这些都是为了设置不同的价格限制。
有没有人以前做过这个,你用的是什么插件?
这是您要找的吗?
add_action('woocommerce_check_cart_items','check_cart_weight');
function check_cart_weight(){
global $woocommerce;
$weight = $woocommerce->cart->cart_contents_weight;
if( $weight > 30 ){
wc_add_notice( sprintf( __( 'You have %sKg weight and we allow only 30Kg of weight per order.', 'woocommerce' ), $weight ), 'error' );
}
}