< Back to home

Woocommerce Tiered Shipping Weight Based No Plugin 2021

 

                        add_filter( 'woocommerce_package_rates', 'arastoo_woocommerce_shipping_max_weight', 9999, 2 );
    
                        function arastoo_woocommerce_shipping_max_weight( $rates, $package ) {
     
                            if ( WC()->cart->get_cart_contents_weight() <= 3 ) {
       
                                if ( isset( $rates['flat_rate:2'] ) ) unset( $rates['flat_rate:4'], $rates['flat_rate:5'] );
       
                            } elseif ( WC()->cart->get_cart_contents_weight() <= 5 ) {
       
                                if ( isset( $rates['flat_rate:2'] ) ) unset( $rates['flat_rate:2'], $rates['flat_rate:5'] );

	                        } elseif ( WC()->cart->get_cart_contents_weight() <= 10 ) {
       
                                if ( isset( $rates['flat_rate:2'] ) ) unset( $rates['flat_rate:2'], $rates['flat_rate:4'] );
       
                            }
	
	                        else {
       
                            if ( isset( $rates['flat_rate:2'] ) ) unset( $rates['flat_rate:2'], $rates['flat_rate:4'], $rates['flat_rate:5'] );
       
                             }
    
                            return $rates;
    
                        }