Unset Shipping Methods based on weight in woocommerce

Terminé Publié le il y a 5 ans Paiement à la livraison
Terminé Paiement à la livraison

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

Nº du projet : #18566362

À propos du projet

3 propositions Projet à distance Actif il y a 5 ans

Décerné à:

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 Plus

%selectedBids___i_sum_sub_4% %project_currencyDetails_sign_sub_5% INR en 1 jour
(69 Commentaires)
5.7