Unset Shipping Methods based on weight in woocommerce

Dokončeno Zveřejněno před 5 lety K zaplacení v momentě doručení
Dokončeno K zaplacení v momentě doručení

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

Identifikační číslo projektu: #18566362

O projektu

3 nabídek Projekt na dálku Aktivní před 5 lety

Uděleno uživateli:

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 Další

₹1700 INR za 1 den
(69 recenzí)
5.7