• Resolved wollyhood

    (@wollyhood)


    Hi,
    I am selling virtual and non-virtual products in my shop and I need to exclude the value of virtual products to count towards the total amount that grants people free shipping.
    I have searched the forum and found other topics on this matter incl this code:

    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;
    }

    I have added this to my functions.php, set the limit to 100€ but when I add a combination of virtual and non-virtual products to my basket, the free shipping option will still be available despite the non-virtual products not reaching 100€.
    The virtual product in question is a gift voucher, set up as a variable product but I have checked and all variations are ticked as virtual. I have also tried to set up a simple product as virtual but I have the same issue. I am using the shipping options provided by woo, not a separate plugin.

    Does anyone have any idea what I should do?
    Many thanks, Tina

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Jonayed Hosen (woo-hc)

    (@jonayedhosen)

    Hi @wollyhood,

    I understand you are encountering an issue where, even after adding some custom PHP code to exclude virtual products from counting toward the free shipping threshold and the free shipping option still appears when the total of non-virtual products doesn’t meet the required minimum.

    However, this request falls a bit outside the scope of support we provide here, as we focus on core plugin support. You can review what our support includes.? However, we have a variety of resources to help point you in the right direction!

    For hands-on guidance, you may want to explore our WooCommerce Developer Portal, which offers detailed documentation and resources to help you build and refine custom solutions.

    Alternatively, if you’re looking for professional support, Codeable.io or one of our WooExperts can connect you with vetted developers who specialize in WooCommerce customizations.

    Additionally, you can reach out in one of the channels below with code customization questions:

    Hope this helps!

    Thread Starter wollyhood

    (@wollyhood)

    Thanks for your reply, I will have a look at the options you have mentioned.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.