我正在使用以下功能在woocommerce中启用基于重量的运输。例如,当购物车中的总重量小于15.84时,应该激活flat_rate:5运送方式,而其他方式则未设置。
但是,我必须编写所有未设置的所有方法。如何更改unset命令以取消设置所有非flat_rate:5的运输方式?
add_filter( 'woocommerce_package_rates', 'bbloomer_woocommerce_tiered_shipping', 10, 2 );
function bbloomer_woocommerce_tiered_shipping( $rates, $package ) {
if ( WC()->cart->cart_contents_weight < 15.84 ) {
if ( isset( $rates['flat_rate:5'] ) ) unset( $rates['flat_rate:6'], $rates['flat_rate:8'] );
} elseif ( WC()->cart->cart_contents_weight < 72 ) {
if ( isset( $rates['flat_rate:5'] ) ) unset( $rates['flat_rate:5'], $rates['flat_rate:8'] );
} elseif ( WC()->cart->cart_contents_weight < 144 ) {
if ( isset( $rates['flat_rate:5'] ) ) unset( $rates['flat_rate:5'], $rates['flat_rate:8'] );
} elseif {
if ( isset( $rates['flat_rate:5'] ) ) unset( $rates['flat_rate:5'], $rates['flat_rate:6'] );
}
return $rates;
}