How To Remove Free Shipping In Woocommerce Product Page

How to Remove Free Shipping in WooCommerce Product Page: A Beginner’s Guide

Free shipping can be a great incentive for customers, boosting your sales and conversion rates. But sometimes, you might want to remove the “free shipping” option from specific products or under certain circumstances. Perhaps you’re dealing with oversized items, special promotions, or want to discourage single-item orders eligible for free shipping otherwise. This article will guide you through several easy-to-understand methods to remove free shipping from the WooCommerce product page.

Why Remove Free Shipping in Certain Cases?

Think of a furniture store. Offering free shipping on a small lamp is perfectly reasonable, but what about a heavy sofa? Absorbing the shipping cost would kill your profit margins. Similarly, imagine you’re running a special sale on a high-demand item and want to offset the discount by charging for shipping.

Here are some common reasons for selectively removing free shipping:

    • High Shipping Costs: For heavy, bulky, or fragile items that are expensive to ship.
    • Low Profit Margins: On specific products where absorbing shipping costs would make them unprofitable.
    • Promotional Strategies: To offset discounts during sales or to encourage larger orders.
    • Geographic Restrictions: You might offer free shipping only to certain regions.
    • Preventing abuse Some users would only add the cheapest product to get free shipping.

    Method 1: Using WooCommerce Shipping Zones and Classes (The Recommended Way)

    This is the most flexible and recommended method as it allows you to control shipping based on product categories, weights, and destinations.

    1. Create a Shipping Class:

    • Navigate to WooCommerce > Settings > Shipping > Shipping Classes.
    • Click “Add Shipping Class”.
    • Name it something descriptive like “Bulky Items” or “No Free Shipping”.
    • Add a slug (e.g., `no-free-shipping`) and a description if desired.
    • Click “Save shipping classes”.

    2. Assign the Shipping Class to Your Product:

    • Edit the product you want to exclude from free shipping.
    • In the “Product data” meta box, go to the “Shipping” tab.
    • In the “Shipping class” dropdown, select the “Bulky Items” (or whatever you named it) shipping class you created.
    • Update your product.

    3. Configure Shipping Zone Options:

    • Go to WooCommerce > Settings > Shipping.
    • Select the shipping zone that offers free shipping (e.g., “United States”). If you don’t have a zone, create one.
    • Click the shipping method that offers free shipping (e.g., “Free Shipping”).
    • Click “Edit”.
    • Under “Shipping class costs”, you can set a cost for the shipping class you created.
    • For example, if you set the “Bulky Items” class to `$15`, any product with that shipping class will now have a $15 shipping cost applied, effectively overriding free shipping.
    • You can set the cost on per-product basis ( enter the cost in “Shipping class costs” box) or on per-quantity basis ( enter the cost in “Shipping class costs” and append “:[number]” such as 15:2 if for every 2 items the cost will be multiplied)
    • Don’t leave those fields empty, or the shipping class will be ignored!

    Example:

    Shipping Class: Bulky Items

    Shipping Class Costs: 15

    This mean a cost of $15 for every product of the shipping class.

    Shipping Class: Bulky Items

    Shipping Class Costs: 15:2

    This mean a cost of $15 for every 2 products of the shipping class.

    • Save your changes.

    Method 2: Using a Code Snippet (For Advanced Users)

    This method involves adding a custom code snippet to your theme’s `functions.php` file or using a code snippets plugin. Caution: Editing theme files can be risky. Always back up your site before making changes. It’s also recommended to use a code snippets plugin instead of directly editing `functions.php`.

    This example targets specific product IDs and removes free shipping.

    /**
    
  • Remove Free Shipping for Specific Products.
  • * @param array $rates Array of available shipping rates.
  • @return array Modified array of shipping rates.
  • */ function remove_free_shipping_for_specific_products( $rates ) { // Specify the product IDs to exclude from free shipping. $excluded_product_ids = array( 123, 456, 789 ); // Replace with your actual product IDs

    $cart_items = WC()->cart->get_cart();

    $has_excluded_product = false;

    foreach ( $cart_items as $cart_item ) {

    if ( in_array( $cart_item[‘product_id’], $excluded_product_ids ) ) {

    $has_excluded_product = true;

    break;

    }

    }

    if ( $has_excluded_product ) {

    foreach ( $rates as $rate_key => $rate ) {

    if ( ‘free_shipping’ === $rate->method_id ) {

    unset( $rates[ $rate_key ] );

    }

    }

    }

    return $rates;

    }

    add_filter( ‘woocommerce_package_rates’, ‘remove_free_shipping_for_specific_products’, 10, 1 );

    Explanation:

    • The code defines a function `remove_free_shipping_for_specific_products`.
    • It specifies an array `$excluded_product_ids` containing the IDs of the products for which you want to disable free shipping. Remember to replace the example IDs with your actual product IDs. You can find the product ID on the product edit page in your WooCommerce admin.
    • The function iterates through the cart items. If any of the cart items have an ID that matches one of the excluded product IDs, the `$has_excluded_product` flag is set to `true`.
    • If the `$has_excluded_product` flag is `true`, the function iterates through the available shipping rates and removes any rate with the `method_id` of `’free_shipping’`.
    • The `add_filter` function hooks this custom function into the `woocommerce_package_rates` filter, which allows you to modify the available shipping rates.

    Method 3: Plugins Designed for Advanced Shipping Rules

    Several WooCommerce plugins allow you to create complex shipping rules based on product attributes, categories, weights, and more. These plugins can simplify the process of selectively removing free shipping and provide more granular control. Examples include:

    • WooCommerce Table Rate Shipping: Lets you define shipping rates based on weight, quantity, destination, and more.
    • Advanced Shipping Packages: Allows for more control over how items are packaged for shipping.
    • Conditional Shipping and Payments: Provides fine-grained control over available shipping and payment options based on various cart and customer conditions.

Using a plugin can be a good option if you need very specific or constantly changing shipping rules without needing to code anything.

Testing Your Changes

After implementing any of these methods, thoroughly test your WooCommerce store to ensure free shipping is being correctly removed from the appropriate products. Add the products to your cart and proceed to the checkout page to verify that the shipping costs are calculated as expected.

By understanding these methods, you can effectively manage your WooCommerce shipping options and tailor them to your specific product offerings and business needs. Good luck!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *