• Resolved aishasw

    (@aishasw)


    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)
  • Margaret S. woo-hc

    (@margaretwporg)

    Hi @aishasw

    Thanks for sharing the details.

    Onw way to achieve this is the Conditional Shipping and Payments extension: https://woocommerce.com/products/conditional-shipping-and-payments/ . It will let you control the shipping and payment options using conditional logic.

    <i>For any pre-sales questions related to this plugin, please create a ticket here. You’d need to log into your WooCommerce account before you can access that page, or create an account if you do not have one. Just so you know, in the WooCommerce.com marketplace we offer a 30-day refund policy so you can test the extension and make sure it works for you.</i>

    However, if you prefer to do the programmatic way, I’m going to leave the thread open for a bit to see if anyone is able to chime in to help you out, as this is a development topic which is beyond the scope of this forum.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    This specific forum is more focused on the default WooCommerce core features.

    Lastly, for direct assistance with code customizations, I recommend consulting with the WooCommerce Customizations Partners. https://woocommerce.com/customizations/

    Cheers

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. Hopefully, the above info was helpful.

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude Virtual products from Free Shipping Total’ is closed to new replies.