WooCommerce: Disable Shipping for Virtual/Downloadable Products
If you run an online store using WooCommerce and sell virtual or downloadable products, you might want to disable shipping options for these products. Shipping is unnecessary for items that don’t require physical delivery, and disabling it improves the checkout experience and avoids confusion for customers. This tutorial shows you how to quickly disable shipping for virtual and downloadable products in WooCommerce with simple code snippets.
Quick Fix
- Add a custom function to your theme’s
functions.php
file or a site-specific plugin. - Use WooCommerce hooks to conditionally remove shipping packages for virtual/downloadable products.
- Test your checkout to confirm shipping options do not appear for these products.
Why This Happens
By default, WooCommerce includes shipping calculations for all products unless they are explicitly marked as virtual or downloadable. Virtual products are intended to be intangible, such as services or memberships, while downloadable products are files customers can download after purchase. However, if a product is not properly configured or if shipping methods are not conditionally disabled, shipping options may still appear, causing confusion or unnecessary steps during checkout.
Requirements
- WooCommerce installed and activated on your WordPress site.
- Basic familiarity with editing theme files or creating a site-specific plugin.
- Access to your WordPress admin dashboard or FTP/SFTP to add custom code.
Step-by-step: Disable Shipping for Virtual/Downloadable Products
- Backup your site. Before making any code changes, ensure you have a recent backup of your site files and database.
- Access your theme’s
functions.php
file. You can do this via WordPress admin under Appearance > Theme Editor or via FTP/SFTP. - Add the following code snippet:
add_filter( 'woocommerce_cart_shipping_packages', 'disable_shipping_for_virtual_downloadable_products' );
function disable_shipping_for_virtual_downloadable_products( $packages ) {
foreach ( $packages as $key => $package ) {
$all_virtual = true;
foreach ( $package['contents'] as $item ) {
$product = $item['data'];
if ( ! $product->is_virtual() && ! $product->is_downloadable() ) {
$all_virtual = false;
break;
}
}
if ( $all_virtual ) {
unset( $packages[ $key ] );
}
}
return $packages;
}
- Save the file.
- Test your checkout. Add virtual or downloadable products to the cart and proceed to checkout. Shipping options should no longer appear. For physical products, shipping remains enabled.
Common Pitfalls
- Not marking products as virtual or downloadable: The code depends on the product’s virtual or downloadable status. If these are not set correctly in the product edit screen, shipping will not be disabled.
- Using caching plugins: Sometimes caching can prevent immediate reflection of changes. Clear your site and browser cache after adding code.
- Theme or plugin conflicts: Some themes or shipping plugins may override WooCommerce shipping behavior. Test with default themes and disable conflicting plugins if needed.
- Editing core WooCommerce files: Never edit WooCommerce core files directly; always use hooks and filters in your theme or custom plugin.
Works on
- Web servers: Apache, Nginx, LiteSpeed
- Hosting panels: cPanel, Plesk, and others
- WooCommerce versions 3.0 and above
- Compatible with most themes and child themes that follow WooCommerce standards
FAQ
- Q: Can I disable shipping only for downloadable products but not virtual ones?
- A: Yes. Modify the condition inside the loop to check only
$product->is_downloadable()
instead of both virtual and downloadable. - Q: What if I want to disable shipping only on certain shipping methods?
- A: You can customize the code further by filtering shipping methods or using WooCommerce’s
woocommerce_package_rates
filter to selectively hide methods. - Q: Does this affect shipping calculations or just the display of shipping options?
- A: This removes shipping packages entirely for virtual/downloadable products, so shipping is neither calculated nor displayed for those products.
- Q: Can I add this code via a plugin instead of the theme’s
functions.php
? - A: Absolutely. Creating a site-specific plugin is recommended to keep customizations separate from theme updates.
- Q: Will this work if I have mixed carts with both physical and virtual/downloadable products?
- A: Yes. Shipping will only be disabled for packages containing exclusively virtual/downloadable products. Physical products will still trigger shipping options.