在woocommerce订单中设置最大重量

Bas*_*aal 0 wordpress max shipping woocommerce

我正在尝试为我使用 woocommerce 建立的网店中的每个订单设置最大重量限制。假设我想为每个订单设置 30 公斤的限制。我尝试在标准的 woocommerce 运输设置中执行此操作。我也尝试了一些不同的插件,但这些都是为了设置不同的价格限制。

任何人以前做过这个,你用什么插件来做这个?

Roh*_*ner 5

这是你想要的 ?

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' );
    }
}
Run Code Online (Sandbox Code Playgroud)