Unset Shipping Methods based on weight in woocommerce
₹600-1500 INR
Opravljeno
Objavljeno pred približno 5 leti
₹600-1500 INR
Plačilo ob dostavi
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;
}
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 can discuss for this project details.
Check my wordpress profile.
[login to view URL]
Thanks