Exclude virtual products from free shipping
-
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, TinaThe page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.