Unset Shipping Methods based on weight in woocommerce

已完成 已发布的 5 年前 货到付款
已完成 货到付款

I am using the following function to enable weight based shipping in woocommerce. For example- when the total weight in the cart is less than, 15.84, the flat_rate:5 shipping method should be activated and the other methods are getting unset.

However, I have to write all the methods getting unset individually. How to change the unset command to unset all shipping methods which are not flat_rate:5,6,8 and so on?

add_filter( 'woocommerce_package_rates', 'bbloomer_woocommerce_tiered_shipping', 10, 2 );

function bbloomer_woocommerce_tiered_shipping( $rates, $package ) {

if ( WC()->cart->cart_contents_weight < 1 ) {

if ( isset( $rates['flat_rate:5'] ) ) unset( $rates['flat_rate:6'], $rates['flat_rate:8'] );

} elseif ( WC()->cart->cart_contents_weight < 5 ) {

if ( isset( $rates['flat_rate:6'] ) ) unset( $rates['flat_rate:5'], $rates['flat_rate:8'] );

} else {

if ( isset( $rates['flat_rate:8'] ) ) unset( $rates['flat_rate:5'], $rates['flat_rate:6'] );

}

return $rates;

}

JavaScript PHP WooCommerce WordPress

项目ID: #18566362

关于项目

3个方案 远程项目 活跃的5 年前

授予:

sumanbiswas85

Hi, Hope you are all well. I have 6 years experience with wordpress,codeigniter,custom php , jQuery ect. I have completed lots of website and fixed lots of issues. I can work now for you. Please come on chat we ca 更多

₹1700 INR 在1天内
(69条评论)
5.7