Table of Contents
In this in-depth tutorial, I’ll show you step-by-step how to create a WooCommerce custom shipping method with the help of a free, readymade plugin and using custom code snippets.

Key Takeaways
- Custom shipping methods help store admins go beyond WooCommerce’s default flat rate, free shipping, and local pickup options. Custom shipping options enable you to tailor your store’s checkout flow so buyers only see shipping methods that actually apply to their orders.
- This tutorial covers 2 popular ways to add custom shipping methods in WooCommerce: using a readymade plugin or with custom code snippets.
- The Flat Rate Shipping Plugin for WooCommerce is the fastest way to set up advanced shipping rules. It lets you easily create unlimited shipping methods with conditions such as weight ranges, product categories, dimensions, postcodes, user roles, cart totals, etc. It also supports multi-currency stores, multilingual setups, and large catalogs.
- Alternatively, you can build your own custom shipping method using WooCommerce’s Shipping Method API and the code snippets shared below.
Looking to add custom shipping methods in WooCommerce? This tutorial has your back.
As your business grows, you’ll likely reach a point where WooCommerce’s default shipping options (i.e., flat rate, free shipping, and local pickup) stop being enough. For instance, you may need to charge based on weight, product dimensions, user role, or other factors.
In this tutorial, I’ll show you 2 straightforward methods to add custom shipping methods in WooCommerce:
- Using a free, readymade plugin, i.e., The Flat Rate Shipping for WooCommerce plugin by The Dotstore.
- Using code to build a WooCommerce custom shipping method plugin from scratch.
The final result will be something like this:

Plugin mentioned in this tutorial
- Flat Rate Shipping Plugin for WooCommerce: A powerful plugin that lets you create custom WooCommerce shipping methods based on product weight, dimensions, user roles, shipping address, cart contents, and other conditions. It is available in both free and pro versions, and has been trusted by thousands of stores since 2017. Want to see if it works for your specific use case? Check out the demo now.
Ready? Let’s get started.
Advanced Flat Rate Shipping Methods
Boost your WooCommerce store’s revenue with flexible shipping options. Your business deserves the best!
14-day, no-questions-asked money-back guarantee.

What is a custom shipping method for WooCommerce?
In WooCommerce, a custom shipping method is any shipping option that store admins create to handle delivery rules beyond the default shipping methods WooCommerce provides. For example, a furniture store might need to calculate shipping for certain SKUs based on their volumetric weight, not just their physical weight.

Custom WooCommerce shipping methods empower you to define shipping rules and logic (such as rates, conditions, availability rules, dynamic variables, etc.) based on your product catalog, operational setup, target customers, product attributes like weight, dimensions, variants, and more.
Types of WooCommerce custom shipping methods
Store admins typically create custom WooCommerce shipping methods based on product type, product category, individual product or total cart weight, location, user role, product dimensions, cart conditions, and other parameters.
Here’s an overview of the most popular types of custom shipping methods for WooCommerce. Of course, you can combine multiple conditions to create complex shipping methods as needed.
- Weight-based shipping. This custom WooCommerce shipping method lets you define weight ranges and assign prices to each one. For example, 0 to 2kg: $5, 2 to 5kg: $10, 5 to 10kg: $18, and so on. It is best suited for stores whose product catalogs include a mix of light and heavy items or situations where courier costs scale with physical weight.
- Product-type or category-based shipping. These custom WooCommerce shipping methods are applied only when certain products or categories are in the cart. This is ideal for oversized goods, items with unique requirements, or products that require special handling.
- Location-specific shipping. Stores that offer local delivery or area-based surcharges can use this method to calculate and display shipping rates only for specific regions, states, cities, or zip codes. The shipping methods are hidden from customers outside of the defined areas.
- Dimensional or volumetric rate shipping. Dimensional weight is more accurate than physical weight in situations where products are low in weight but large in volume. You can use custom WooCommerce shipping methods to calculate costs using length × width × height.
- Conditional shipping. As the name implies, this custom WooCommerce shipping method involves calculating rates based on specific conditions that apply to the cart, such as quantity, subtotal, item mix, coupons, etc.
- User-role–based shipping. You can tailor shipping methods and rates to specific customer types. For example, a hybrid wholesale and retail store might want to show only wholesale / B2B users a “Freight Shipping” method with pallet-based rates.
Why create custom shipping methods in WooCommerce?
Here are some of the most common reasons why store admins add custom shipping methods to WooCommerce.
1. Unique business-specific conditions
Many businesses have custom rate structures that don’t fit standard patterns, and the default WooCommerce shipping methods don’t always account for every store’s unique operational realities.
For instance, stores that sell subscriptions, handmade goods, industrial supplies, and the like often need custom rules that combine weight, quantity, delivery destination, dynamic costs, etc.
In these situations, creating custom WooCommerce shipping methods might be the best way to calculate actual logistics costs.
2. Protect profit margins
In stores with diverse product catalogs, the default WooCommerce shipping methods alone can lead to the following scenarios:
- You undercharge. You’ll barely break even on certain product lines, which will slowly eat into your profits over time.
- You overcharge. This discourages customers from completing the checkout process, leading to a high cart abandonment rate and loss in revenue.
A custom shipping method can enable you to automatically factor in packaging costs, handling fees, fuel surcharges, and other necessary costs into shipping rates.
3. Encourage desirable purchasing behavior
You can use custom methods to create shipping incentives that benefit both your customers and business. For instance, you may want to offer a discounted rate for orders over a certain weight or quantity to encourage bulk purchases.
4. Improve the checkout experience by removing irrelevant options
Showing shipping methods that don’t apply to their order can slow people down, cause confusion, and add unnecessary friction during the checkout flow.
Custom shipping methods let you add conditions that show or hide methods to customers who match the exact set of conditions: product types, cart items, categories, shipping classes, destinations, user roles, cart value, the day of the week, and more.
For instance, you may want to:
- Offer “Eco Delivery” only if all items fall under a specific weight.
- Hide “Express Shipping” when the cart contains oversized or restricted items that can’t be shipped quickly.
- Offer a “Wholesale Freight Rate” only to users with the “Wholesale” customer role.
Introducing a powerful custom shipping method plugin

The Dotstore’s Flat Rate Shipping Plugin for WooCommerce is a powerful plugin that lets you create unlimited custom shipping methods, each with its own rules, rates, restrictions, and conditions. It works great for variable products, multilingual sites, multi-currency setups, stores with large catalogs, and more.
Thousands of store admins across various industries and use cases (oversized items, region-specific couriers, wholesale customers, strict cost structures, etc) use it to set up their stores’ shipping methods.

Flat Rate Shipping Plugin for WooCommerce lets you add different types of custom shipping methods, including weight-based shipping, product or category-based shipping, location-based shipping, dimensional shipping, user-role–based shipping, conditional shipping, etc.
PS: If you plan to create a custom local pickup shipping method, you may want to use our WooCommerce Local Pickup plugin instead. It’s purpose-built for that use case and offers heaps of useful, additional features.
Here are some of the features that make the Flat Rate Shipping Plugin for WooCommerce the best choice for custom shipping setups.
- Unlimited custom shipping methods. You can add as many custom shipping methods as needed: standard shipping, local delivery, heavy item shipping, priority express, and others. Each custom shipping method can have its own rules, descriptions, and pricing.
- Conditional logic for various scenarios. You can add conditions like cart subtotal, quantity of items, product categories, shipping classes, user roles, postcodes and zones, weight ranges, dimensions, countries and states, etc., to create complex custom shipping methods.
- Advanced cost calculation options. If you don’t want to use simple flat costs, you can set a base cost, cost per item, cost per weight unit, tiered costs, and additional handling fees.
How to add a custom shipping method in WooCommerce
In this tutorial, I’ll show you how to create a location and weight-based custom shipping method in WooCommerce. The process is largely the same for other types of custom shipping methods.
- Add Flat Rate Shipping for WooCommerce’s free or pro version to your website.
- From your WordPress admin, navigate to Dotstore Plugins → Flat Rate Shipping → Settings → Manage Rules.

- Press “Add New” to create a custom WooCommerce shipping method.
- Turn on the “Status” switch and name your new custom shipping method.

- Set the Shipping Charge to 0 for the base rate.
- Choose whether this custom shipping method should be your default shipping option and decide if it should include tax.

- Scroll to the Shipping Method Rules area.
- From the left dropdown, pick the delivery location type you want to target (country, state, city, postcode, or zone). From the middle dropdown, choose “Equal to (=).” Then add all the countries, states, postcodes, cities, or zones that should be covered by this custom shipping method in the right dropdown.

- Switch on the “Advanced Shipping Price Rules” area.
- Go to the “Cost on Total Cart Weight” tab. Press “Add rule”, then add all the weight-based rules needed.

- Enter the minimum weight, maximum weight, and the shipping fee for each rule you’re creating.
- Once done, press “Save changes” to create your custom shipping method for WooCommerce.

How to create a custom shipping method in WooCommerce with custom code
If you’re comfortable with code or don’t want to use the readymade plugin mentioned above, you can use the snippets below.
In this section, I’ll walk you through in-depth step-by-step instructions to create a small custom WooCommerce shipping method plugin that registers a shipping method, exposes admin settings (title, base cost, per-kg cost, enable dimensional mode), computes rates in calculate_shipping(), and returns one or more rates with add_rate().
A quick note: This approach requires a fundamental understanding of how the WooCommerce Shipping Method API and WooCommerce Shipping Architecture work. Also, writing PHP functions, understanding classes, using filters and actions, and debugging syntax errors.
Now, let’s get started with the tutorial.
1. Create the plugin scaffold
Create a folder wp-content/plugins/dotstore-custom-shipping and a file dotstore-custom-shipping.php. Paste this header and the bootstrap code:
<?php
/**
* Plugin Name: DotStore - Custom Shipping Method
* Plugin URI: https://thedotstore.com
* Description: Example custom shipping method for WooCommerce — flat + per-weight + dimensional example.
* Version: 1.0.0
* Author: The DotStore
* Text Domain: dotstore-custom-shipping
* Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Ensure WooCommerce is active before loading.
*/
add_action( 'plugins_loaded', 'dotstore_custom_shipping_init', 11 );
function dotstore_custom_shipping_init() {
if ( ! class_exists( 'WC_Shipping_Method' ) ) {
// WooCommerce not active — nothing to do.
return;
}
include_once dirname( __FILE__ ) . '/includes/class-dotstore-shipping-method.php';
// Register the shipping method with WooCommerce.
add_filter( 'woocommerce_shipping_methods', 'dotstore_register_shipping_method' );
function dotstore_register_shipping_method( $methods ) {
$methods['dotstore_shipping'] = 'DotStore_Shipping_Method';
return $methods;
}
}
This structure works because:
- plugins_loaded with priority 11 ensures WooCommerce has loaded.
- Shipping methods are registered with the woocommerce_shipping_methods filter, returning your class name keyed by slug.
2. Add the shipping method class file
Create includes/class-dotstore-shipping-method.php and paste this full class.
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class DotStore_Shipping_Method extends WC_Shipping_Method {
public function __construct( $instance_id = 0 ) {
$this->id = 'dotstore_shipping'; // method ID (slug)
$this->method_title = __( 'DotStore Shipping', 'dotstore-custom-shipping' );
$this->method_description = __( 'Custom shipping method — flat + per-weight + dimensional example.', 'dotstore-custom-shipping' );
// supports instances so you can add method multiple times per zone (WooCommerce 2.6+)
$this->supports = array(
'shipping-zones',
'settings',
'instance-settings',
);
// Instance ID for per-zone instances
$this->instance_id = absint( $instance_id );
// Init form fields and settings.
$this->init();
// Save admin options in the backend.
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
/**
* Initialize settings form fields (admin).
*/
public function init() {
// Load the settings API.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->title = $this->get_option( 'title', $this->method_title );
$this->enabled = $this->get_option( 'enabled', 'yes' );
$this->tax_status = $this->get_option( 'tax_status', 'none' );
// Custom options
$this->base_cost = floatval( $this->get_option( 'base_cost', 0 ) );
$this->cost_per_kg = floatval( $this->get_option( 'cost_per_kg', 0 ) );
$this->enable_dimensional = ( 'yes' === $this->get_option( 'enable_dimensional', 'no' ) );
// Optional dimension multiplier for volumetric weight calculation (e.g. 5000 or 6000)
$this->dimensional_divisor = floatval( $this->get_option( 'dimensional_divisor', 5000 ) );
}
/**
* Admin fields for the shipping method.
*/
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'dotstore-custom-shipping' ),
'type' => 'checkbox',
'label' => __( 'Enable DotStore Shipping', 'dotstore-custom-shipping' ),
'default' => 'yes',
),
'title' => array(
'title' => __( 'Method Title', 'dotstore-custom-shipping' ),
'type' => 'text',
'description' => __( 'Title shown during checkout.', 'dotstore-custom-shipping' ),
'default' => __( 'DotStore Shipping', 'dotstore-custom-shipping' ),
),
'base_cost' => array(
'title' => __( 'Base Cost', 'dotstore-custom-shipping' ),
'type' => 'number',
'description' => __( 'Flat fee applied to all orders (per package).', 'dotstore-custom-shipping' ),
'default' => '0',
'custom_attributes' => array( 'step' => '0.01', 'min' => '0' ),
),
'cost_per_kg' => array(
'title' => __( 'Cost per kg', 'dotstore-custom-shipping' ),
'type' => 'number',
'description' => __( 'Add this cost per kg of total package weight.', 'dotstore-custom-shipping' ),
'default' => '0',
'custom_attributes' => array( 'step' => '0.01', 'min' => '0' ),
),
'enable_dimensional' => array(
'title' => __( 'Dimensional mode', 'dotstore-custom-shipping' ),
'type' => 'checkbox',
'description' => __( 'If enabled, use volumetric weight (L×W×H / divisor) instead of actual weight.', 'dotstore-custom-shipping' ),
'default' => 'no',
),
'dimensional_divisor' => array(
'title' => __( 'Dimensional divisor', 'dotstore-custom-shipping' ),
'type' => 'number',
'description' => __( 'Divisor used for volumetric weight (common values: 5000 or 6000).', 'dotstore-custom-shipping' ),
'default' => '5000',
'custom_attributes' => array( 'step' => '1', 'min' => '1' ),
),
'tax_status' => array(
'title' => __( 'Tax status', 'dotstore-custom-shipping' ),
'type' => 'select',
'options' => array(
'taxable' => __( 'Taxable', 'dotstore-custom-shipping' ),
'none' => __( 'None', 'dotstore-custom-shipping' ),
),
'default' => 'none',
),
);
}
/**
* calculate_shipping: compute shipping and add rates
*
* @param array $package Package details passed by WooCommerce.
*/
public function calculate_shipping( $package = array() ) {
// Basic guard.
if ( empty( $package ) || ! isset( $package['contents'] ) ) {
return;
}
// 1) Compute total weight and dimensions from the package
$total_weight = 0.0; // in kg (store should use consistent units)
$total_volume = 0.0; // cubic cm as example
foreach ( $package['contents'] as $item_id => $values ) {
$product = $values['data'];
// quantity
$qty = isset( $values['quantity'] ) ? absint( $values['quantity'] ) : 1;
// product weight (fallback 0)
$product_weight = (float) $product->get_weight() ?: 0.0;
// product dimensions
$length = (float) $product->get_length() ?: 0.0;
$width = (float) $product->get_width() ?: 0.0;
$height = (float) $product->get_height() ?: 0.0;
// Multiply by quantity
$total_weight += $product_weight * $qty;
// Convert dimensions to cm (assumes product dims are in store units; validate via settings in real plugin)
$product_volume = $length * $width * $height * $qty; // cubic units (e.g., cm^3)
$total_volume += $product_volume;
}
// 2) If dimensional mode enabled, compute volumetric weight
if ( $this->enable_dimensional && $this->dimensional_divisor > 0 ) {
// Convert cubic cm to kg using divisor: volumetric_weight_kg = (L*W*H cm) / divisor
$volumetric_weight = ( $total_volume / $this->dimensional_divisor );
$chargeable_weight = max( $total_weight, $volumetric_weight );
} else {
$chargeable_weight = $total_weight;
}
// 3) Compute cost
$cost = $this->base_cost + ( $this->cost_per_kg * $chargeable_weight );
// Round cost to 2 decimals
$cost = round( (float) $cost, 2 );
// Optional: add conditional handling (e.g., free if subtotal > X)
$cart_subtotal = WC()->cart->get_subtotal();
if ( $cart_subtotal >= 200 ) {
$cost = 0;
}
// 4) Build rate array and add it
$rate = array(
'id' => $this->id . ':' . $this->instance_id, // unique per instance
'label' => $this->title,
'cost' => $cost,
'taxes' => '',
'meta_data' => array(
'chargeable_weight' => $chargeable_weight,
'method' => $this->enable_dimensional ? 'dimensional' : 'weight',
),
);
$this->add_rate( $rate );
}
}
Key class details explained
- extends WC_Shipping_Method: this is the required base class. WooCommerce expects methods to inherit from it.
- $this->supports = array( ‘shipping-zones’, ‘settings’, ‘instance-settings’ ): allows multiple instances of your method per zone and exposes admin settings. If you omit shipping-zones, your method may not show as an instance inside zones.
- init_form_fields() defines the settings UI automatically shown in the shipping zone → method instance. Use types text, number, checkbox, select.
- calculate_shipping( $package ) is the single most important method; WooCommerce calls it to get rates. Use $this->add_rate( $args ) to add each shipping option you want the customer to see.
3. Register and test the custom shipping method in WooCommerce
- Head into your site’s admin panel, and add and activate the plugin in Plugins → Add Plugin.
- Go to WooCommerce → Settings → Shipping → Shipping zones. Edit a zone, press “Add shipping method”, and add the “DotStore Shipping” plugin from the dropdown menu.
- Click “Edit” on the newly added shipping method. You’ll see the settings from init_form_fields() (title, base cost, cost per kg, and dimensional options). Update the values as needed and press “Save”.
Best practices for creating custom shipping methods in WooCommerce
- Use descriptive, customer-friendly names and labels for each custom shipping method that quickly communicate what the customer is choosing. For example. “Express Delivery (1–2 business days)” instead of “Weight-Based Shipping”.
- Whenever possible, show estimated delivery times for custom shipping methods on the checkout page so shoppers know when their order will arrive. For example, “Priority Express (Next business day)”, “Eco Delivery – 5 to 7 days”, etc.
- Create fallback shipping methods to account for edge cases and unplanned scenarios. For example, a basic flat rate that applies when none of your other rules match. Otherwise, you run the risk that customers will get the dreaded “No shipping methods available” error message.
Add custom shipping methods in WooCommerce
Some stores need more than WooCommerce’s default shipping options provide. In this tutorial, I’ve shown you 2 ways to create custom shipping methods:
- With the free or pro version of Flat Rate Shipping Plugin for WooCommerce, a powerful, ready-to-install plugin.
- A small custom-coded shipping method plugin.
If you’re comfortable working with code and have some time on your hands, feel free to create your own custom plugin.
Otherwise, use The Dotstore’s Flat Rate Shipping Plugin for WooCommerce to add flexible weight-based, location-based, product-specific, category-based, dimensional, user–role–based, conditional, and various other types of custom shipping methods within a few minutes.
Get started with the free or pro version of the Flat Rate Shipping Plugin for WooCommerce now!
Advanced Flat Rate Shipping Methods
Boost your WooCommerce store’s revenue with flexible shipping options. Your business deserves the best!
14-day, no-questions-asked money-back guarantee.

