How to Set Free Shipping for a Particular Product in WooCommerce
Introduction:
Offering free shipping is a powerful marketing tactic that can significantly boost your WooCommerce store’s conversion rates and average order value. While setting up sitewide free shipping is straightforward, sometimes you only want to offer it on specific products. This might be to clear inventory, promote new items, or offer an incentive for purchasing higher-value goods. In this article, we’ll explore several methods for setting free shipping for a particular product in WooCommerce, allowing you to tailor your shipping strategy and maximize its impact. We’ll cover methods ranging from the simple to the more advanced, so you can choose the one that best suits your needs and technical skill.
Methods for Enabling Free Shipping on Specific WooCommerce Products
There are several ways to achieve this, each with its own advantages and disadvantages. We’ll examine three primary approaches:
1. Using WooCommerce’s Built-in Shipping Classes: This is a relatively simple method using WooCommerce’s native functionality.
2. Utilizing a Dedicated Free Shipping Plugin: Plugins often provide more control and flexibility.
3. Implementing a Custom Code Snippet: This method offers the most control but requires some coding knowledge.
1. Leveraging Shipping Classes for Targeted Free Shipping
This method utilizes WooCommerce’s built-in shipping classes.
* Step 1: Create a Shipping Class:
- Go to WooCommerce > Settings > Shipping > Shipping Classes.
- Click “Add Shipping Class”.
- Name the class something descriptive, like “Free Shipping Product”. Add a slug (e.g., “free-shipping”) and a description.
- Click “Save shipping classes”.
- Edit the specific product you want to offer free shipping on.
- Scroll down to the “Product data” meta box.
- Go to the “Shipping” tab.
- In the “Shipping class” dropdown, select the “Free Shipping Product” class you created.
- Update the product.
- Go to WooCommerce > Settings > Shipping > Shipping Zones.
- Edit the relevant shipping zone.
- Click “Add shipping method”.
- Choose “Free Shipping” and click “Add shipping method”.
- Edit the “Free Shipping” method you just added.
- In the “Free Shipping requires…” dropdown, choose “A valid free shipping coupon” OR “A minimum order amount” OR “An order for a minimum amount AND a coupon” (depending on how else you have free shipping set up in your store. If you select coupon or coupon and minimum amount, make sure the coupon is created to apply to only the free shipping class and any others you’ve set it on).
- Set any necessary minimum order amount (if applicable) to a low amount, effectively making products with this class eligible for free shipping within that zone. Or, if you will be using coupons, create a WooCommerce coupon and in the “usage restriction” tab in coupon creation, select the category that you will be free shipping on and be sure to check the “allow free shipping” box.
- Click “Save changes”.
* Step 2: Assign the Shipping Class to Your Product:
* Step 3: Configure Shipping Zones and Free Shipping Method:
Important Considerations:
* Multiple Shipping Methods: This method works best when you have clear distinctions between shipping zones. If you only have one shipping zone, setting a very low minimum order amount could inadvertently give *all* products free shipping within that zone.
* Combining Products: If a customer orders both a “Free Shipping Product” and a product with a standard shipping class, WooCommerce will likely calculate shipping based on the standard shipping class. The way around this is to edit your regular shipping options and set them to charge shipping by class, charging nothing for the “Free Shipping Product” class.
2. Using a Dedicated Free Shipping Plugin
Several plugins on the WordPress repository can handle free shipping for specific products with more refined control. Examples include:
* “Conditional Shipping and Payments”
* “Advanced Coupons”
* “WooCommerce Table Rate Shipping” (can often be configured for this purpose)
While the exact steps will vary depending on the plugin, the general process is:
1. Install and Activate the Plugin: Find the plugin in the WordPress Plugin Repository (Plugins > Add New) and install and activate it.
2. Configure the Plugin: Access the plugin’s settings (usually under WooCommerce or a dedicated menu item).
3. Set up Rules for Specific Products: The plugin will typically provide options to create rules based on product ID, category, or other attributes. You can then specify that these products qualify for free shipping.
Plugins provide a more user-friendly interface than code and often come with additional features, such as the ability to set up complex shipping rules based on various criteria.
3. Implementing a Custom Code Snippet (Advanced)
For developers or those comfortable with code, a custom code snippet provides the greatest flexibility. This involves adding a function to your theme’s `functions.php` file or using a code snippet plugin.
/**
/
* Filter to conditionally offer free shipping based on the presence of a specific product.
*
* @param array $rates An array of available shipping rates.
* @return array An array of modified shipping rates.
*/
add_filter( ‘woocommerce_package_rates’, ‘conditionally_offer_free_shipping’, 10, 2 );
function conditionally_offer_free_shipping( $rates, $package ) {
// Specify the product ID for which you want to offer free shipping.
$free_shipping_product_id = 123; // Replace 123 with the actual product ID.
// Check if the specific product is in the cart.
if ( has_product_in_cart( $free_shipping_product_id ) ) {
// Ensure free shipping is enabled.
$free_shipping_found = false;
foreach ($rates as $rate_id => $rate) {
if (‘free_shipping’ === $rate->method_id) {
$free_shipping_found = true;
break;
}
}
if ( $free_shipping_found ) {
// Remove all other rates and leave only free shipping. This is important.
$free_rate = array();
foreach ($rates as $rate_id => $rate) {
if (‘free_shipping’ === $rate->method_id) {
$free_rate[ $rate_id ] = $rate;
break;
}
}
return $free_rate;
} else {
// If “Free Shipping” method is not enabled, show a notice and retain the default rates.
wc_add_notice( ‘Free shipping is available but has not been enabled as a shipping method!’, ‘notice’ );
return $rates; // Do not alter rates, since free shipping is unavailable.
}
}
return $rates; // Return the original rates if the product isn’t in the cart.
}
Explanation:
1. `has_product_in_cart()` Function: This function iterates through the cart items and checks if the specified `$product_id` is present.
2. `conditionally_offer_free_shipping()` Function: This function is hooked into the `woocommerce_package_rates` filter, which allows you to modify the available shipping rates.
- It checks if the specific product (defined by `$free_shipping_product_id`) is in the cart using the `has_product_in_cart()` function.
- If the product is in the cart and free shipping is enabled, it removes all other shipping rates, leaving only the free shipping option.
- If the product is in the cart but free shipping isn’t available, it returns the cart shipping rates and adds a notice to the top of the page.
- If the product *isn’t* in the cart, it returns the original shipping rates.
Important: Replace `123` with the actual product ID you want to offer free shipping on. Also, ensure that free shipping is enabled as a shipping method within your shipping zones.
Advantages of this approach:
* Highly Customizable: You can tailor the logic to fit your specific needs.
* Precise Control: You can target specific products with pinpoint accuracy.
Disadvantages:
* Requires Coding Knowledge: This method is not suitable for non-developers.
* Potential for Errors: Incorrect code can break your site. Always test thoroughly in a staging environment before deploying to your live site.
Before implementing this code:
* Back Up Your Website: Always back up your entire website (database and files) before making any code changes.
* Use a Child Theme: Never edit your parent theme directly. Create a child theme and add the code to its `functions.php` file. This will prevent your changes from being overwritten when you update your theme.
Debugging: If the code doesn’t work as expected, check your error logs for any PHP errors.
Other Considerations for using Code Snippets:
* Snippet Plugins: Consider using a snippet plugin like “Code Snippets” to manage your custom code. This makes it easier to enable/disable snippets and avoids directly editing your theme’s `functions.php` file.
Conclusion
Offering free shipping on specific products is a smart way to incentivize purchases and boost sales. By choosing the method that best suits your technical expertise and business needs – whether it’s using WooCommerce’s built-in shipping classes, leveraging a dedicated plugin, or implementing a custom code snippet – you can effectively target your free shipping offers and achieve your desired results. Remember to thoroughly test any changes you make to your WooCommerce store to ensure a smooth and positive shopping experience for your customers.