Exclude Virtual products from Free Shipping Total
-
I have included code to not count virtual products towards free shipping total. However, when the cart has a virtual product AND a non-virtual product AND the total is less than the free shipping amount, the error says
“no shipping options were found”.How do I still get a valid paid shipping option when there is both a virtual and non-virtual product in the cart and the non-virtual product does not meet the minimum for free shipping?
THIS is the code that was added:
add_filter('woocommerce_package_rates', 'custom_free_shipping_option', 10, 2 ); function custom_free_shipping_option($rates, $package){ // HERE set the "minimum order amount" for free shipping $limit = 100; $free_total = 0; // Get the cart content total excluding virtual products foreach( WC()->cart->get_cart() as $cart_item ) if( ! $cart_item['data']->is_virtual( ) ) $free_total += $cart_item['line_total']; // Disabling free shipping method based on specific cart content total if( $free_total < $limit ) foreach ( $rates as $rate_key => $rate ) if( 'free_shipping' == $rate->method_id ) unset( $rates[ $rate_key ] ); return $rates; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Exclude Virtual products from Free Shipping Total’ is closed to new replies.