Viewing 3 replies - 1 through 3 (of 3 total)
  • Mirko P.

    (@rainfallnixfig)

    Hello @ojithb

    The code snippet below Original answer (for classic "Free Shipping" method) on the Stack Overflow thread you shared worked fine on my test site and it excludes virtual products from the minimum order amount. You may want to update it for orders over $150, like this:

    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 = 150;
    
        $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;
    }

    If it still doesn’t work, I recommend getting in touch with a web developer or one of the customization experts listed at: https://woocommerce.com/customizations/.

    Thanks.

    Thread Starter Ojith Brahmana

    (@ojithb)

    Hey @rainfallnixfig

    Not sure why, but this code worked perfect.
    Thanks a lot!

    Mirko P.

    (@rainfallnixfig)

    You’re welcome! Glad to hear it.

    If you have more questions please feel free to open a new topic.

    Have a nice day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude WooCommerce virtual product from counting towards free delivery’ is closed to new replies.