Skip to content
  • Quick Ref
  • Contact
  • About
wpcanyon.com

wpcanyon.com

Tag: Shipping

WooCommerce: Disable shipping for virtual/downloadable products

Posted on August 19, 2025 By Admin No Comments on WooCommerce: Disable shipping for virtual/downloadable products

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

  1. Add a custom function to your theme’s functions.php file or a site-specific plugin.
  2. Use WooCommerce hooks to conditionally remove shipping packages for virtual/downloadable products.
  3. 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

  1. Backup your site. Before making any code changes, ensure you have a recent backup of your site files and database.
  2. Access your theme’s functions.php file. You can do this via WordPress admin under Appearance > Theme Editor or via FTP/SFTP.
  3. 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;
}
  1. Save the file.
  2. 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.
…
WooCommerce How‑tos

WooCommerce: Create tiered shipping by product category

Posted on August 19, 2025August 19, 2025 By Admin No Comments on WooCommerce: Create tiered shipping by product category

WooCommerce: Create Tiered Shipping by Product Category

If you run a WooCommerce store, you might want to charge different shipping rates based on product categories. For example, electronics might have a different shipping cost than clothing, or you might want to offer tiered shipping rates depending on the category and order quantity. WooCommerce doesn’t provide tiered shipping by category out of the box, but with a few simple steps, you can set this up quickly.

Quick Fix: Use Shipping Classes and Shipping Zones with Rules

  1. Create shipping classes corresponding to your product categories.
  2. Assign these shipping classes to products in each category.
  3. Set up shipping zones and add flat rate shipping methods.
  4. Configure tiered shipping costs per shipping class using cost formulas.

This approach leverages WooCommerce’s built-in shipping classes and flat rate shipping method cost formulas to simulate tiered shipping by product category without custom coding.

Why This Happens

WooCommerce’s default shipping system calculates shipping costs based on shipping zones and methods. Shipping classes allow grouping products for shipping cost differentiation, but WooCommerce does not natively support tiered or quantity-based shipping rates by category. By assigning shipping classes that mirror categories and using cost formulas, you can create tiered shipping rates that vary by category and quantity.

This method works because the flat rate shipping method supports cost formulas using placeholders like [qty] (quantity of items) and [cost] (base cost). By combining these with shipping classes, you can create tiered costs per category.

Step-by-step: Create Tiered Shipping by Product Category

  1. Create Shipping Classes
    • Go to WooCommerce > Settings > Shipping > Shipping classes.
    • Click Add shipping class for each product category you want to tier. For example:
      • Electronics
      • Clothing
      • Books
    • Save shipping classes.
  2. Assign Shipping Classes to Products
    • Go to Products > All Products.
    • Edit each product and assign the appropriate shipping class under the Shipping tab.
    • Update products.
  3. Set Up Shipping Zones
    • Go to WooCommerce > Settings > Shipping > Shipping zones.
    • Create or edit a shipping zone that applies to your customers (e.g., United States).
    • Add a Flat rate shipping method to this zone.
  4. Configure Tiered Shipping Costs Per Shipping Class
    • Click Edit on the flat rate shipping method.
    • Set the Cost field for the base rate (e.g., 5 for $5 base shipping).
    • Expand the Shipping class costs section.
    • For each shipping class, enter a cost formula that applies tiered rates. For example:
      • Electronics: 10 + ([qty] - 1) * 3 (first item $10, each additional $3)
      • Clothing: 5 + ([qty] - 1) * 1.5 (first item $5, each additional $1.50)
      • Books: 3 + ([qty] - 1) * 1 (first item $3, each additional $1)
    • Save changes.
  5. Test Your Setup
    • Add products from different categories to your cart.
    • Verify the shipping cost updates according to your tiered rules.

Edge Cases and Additional Tips

  • Multiple Categories per Product: WooCommerce shipping classes are single-select, so if a product belongs to multiple categories, assign the shipping class that best fits your shipping cost strategy.
  • Combining Shipping Classes: WooCommerce sums shipping class costs by default, so if your cart contains multiple classes, the total shipping cost will be the sum of each class’s tiered cost.
  • Free Shipping Thresholds: To offer free shipping for certain categories or order totals, add a Free shipping method to your shipping zone with conditions.
  • Using Plugins: For more complex tiered shipping rules (e.g., weight, volume, or mixed conditions), consider plugins like Table Rate Shipping or Advanced Shipping Packages.

Works On

Environment Compatibility
Web Servers Apache, Nginx, LiteSpeed
Control Panels cPanel, Plesk, DirectAdmin
WooCommerce Versions WooCommerce 3.0 and above
WordPress Versions WordPress 5.0 and above

FAQ

  1. Can I set different tiered shipping rates for multiple categories in one order?

    Yes. WooCommerce sums the shipping costs for each shipping class in the cart, so tiered rates per category will combine automatically.

  2. What if a product belongs to multiple categories?

    Since shipping classes are single-select, assign the shipping class that best matches the shipping cost. For complex cases, consider plugins that support multiple shipping classes or custom rules.

  3. Can I use weight or dimensions in tiered shipping calculations?

    Not with the default flat rate method. For weight or dimension-based tiered shipping, use advanced shipping plugins like Table Rate Shipping.

…
WooCommerce How‑tos

Recent Posts

  • Top WordPress Themes for Blogs in 2025
  • WordPress Admin Panel Trick: Adding ID Field to the Posts Listing
  • Solution previous_posts_link and next_posts_link Not Working
  • Show Top Commentators in WordPress Without a Plugin
  • How to Style Admin Comments in WordPress

Recent Comments

    Archives

    • August 2025

    Categories

    • Admin & Blocks
    • Admin & UI
    • Automation
    • Automation & Plugins
    • Comments
    • Comparisons
    • Database & Revisions
    • Developer Snippets
    • Fixes & Errors
    • Media & Thumbnails
    • Queries & Pagination
    • Security
    • Speed & Security
    • Tips & Tricks
    • WooCommerce How‑tos
    • WordPress Snippets
    • WordPress Themes
    • Terms & Conditions
    • Affiliate Disclosure

    Copyright © 2025 wpcanyon.com.

    Powered by PressBook WordPress theme

    Also by the maker of MySurveyReviews.com