Building a Custom Delivery Method in the WooCommerce Platform

Building a Custom Delivery Method in the WooCommerce Platform

Nov 11, 2025 |

10 minutes read

Building a Custom Delivery Method in the WooCommerce Platform

Understanding WooCommerce’s Flexibility and the Need for Custom Delivery Methods

Millions of online stores around the globe rely on the WooCommerce platform, the powerful eCommerce plugin for WordPress; its flexibility is a primary reason for this extensive adoption. Developers have the ability to customize nearly every component to match unique business requirements.

The delivery process is among the most essential elements of running an online shop. They determine how products get delivered to customers and how delivery costs are calculated. While the WooCommerce platform includes standard options like Flat Rate, Free Delivery, and Local Pickup, many stores need something more specific — such as integrating with special carriers, setting up advanced rules based on weight or location, or even offering same-day delivery.

In this guide, we’ll take you step-by-step through creating a custom delivery method in the WooCommerce platform, completely from scratch. You’ll learn how to register your own delivery method, set up its settings, and control how delivery rates are calculated. This tutorial assumes you already have some basic knowledge of PHP, WordPress plugin development, and the WooCommerce platform hooks and filters.

What is a Delivery Method Class?

In the WooCommerce platform, the Delivery Method Class is a PHP class that defines a delivery method for your store. It’s a core part of the WooCommerce platform’s delivery system and is responsible for calculating delivery costs, displaying delivery options at checkout, and allowing store owners to configure those methods through the WordPress admin interface.

The WooCommerce platform provides a built-in class, WC_Delivery_Method, which serves as a base class for custom delivery methods. The Delivery Method Class acts as a blueprint that dictates how a delivery method works, from determining the price based on conditions (such as weight or distance) to how it is displayed to customers at checkout.

Why Create a Custom Delivery Method?

The WooCommerce platform’s built-in delivery methods work well for many stores, but a custom method may be needed when you want to: 

– Set conditional rates (e.g., based on cart total or weight)

– Integrate with third-party delivery APIs

– Offer special rates for certain products or user roles

– Implement dynamic pricing or location-based delivery logic 

Creating your own delivery method gives you complete control over how delivery costs are calculated.

Prerequisites

Before starting, ensure you have:

– A WordPress site with the WooCommerce platform installed and activated (version 3.0 or higher recommended).

– Basic PHP knowledge and access to a code editor.

– A development environment (local or staging) to avoid disrupting a live site.

– Familiarity with WordPress plugins; we’ll create one for our custom method.

Step 1: Setting Up the Extension Structure

Custom delivery methods are best implemented as plugins for easy management and updates. Create a new folder in wp-content/plugins/ called custom-delivery-method. Inside it, add a main PHP file, say custom-delivery-method.php.

Start with the plugin header:


/** 
 * Plugin Name: Custom Shipping Method 
 * Description: Adds a simple custom shipping option to WooCommerce. 
 * Version: 1.0.0 
 * Author: Your Name 
 * Text Domain: custom-shipping 
 */ 
 
if ( ! defined( 'ABSPATH' ) ) exit; 
 
// Load the shipping class when WooCommerce initializes shipping 
add_action( 'woocommerce_shipping_init', 'init_custom_shipping_method' ); 
 
function init_custom_shipping_method() { 
    require_once plugin_dir_path( __FILE__ ) . 'class-custom-shipping.php'; 
} 
 
// Register the method 
add_filter( 'woocommerce_shipping_methods', 'add_custom_shipping_method' ); 
 
function add_custom_shipping_method( $methods ) { 
    $methods['custom_shipping'] = 'WC_Custom_Shipping'; 
    return $methods; 
} 

Step 2: Defining the Custom Delivery Class

Extend WC_Delivery_Method to create your class. Add this inside the main file or in a separate class-custom-delivery.php file (and include it).


if ( ! defined( 'ABSPATH' ) ) exit; 
 
class WC_Custom_Shipping extends WC_Shipping_Method { 
 
    public function __construct( $instance_id = 0 ) { 
        $this->id           = 'custom_shipping'; 
        $this->instance_id  = absint( $instance_id ); 
        $this->method_title = __( 'Custom Shipping', 'custom-shipping' ); 
        $this->supports     = array( 'shipping-zones', 'instance-settings' ); 
 
        $this->init(); 
    } 
 
    function init() { 
        $this->init_form_fields(); 
        $this->init_settings(); 
 
        $this->title = $this->get_option( 'title' ); 
        $this->cost  = $this->get_option( 'cost' ); 
 
        add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); 
    } 
 
    function init_form_fields() { 
        $this->instance_form_fields = array( 
            'title' => array( 
                'title'   => __( 'Method Title', 'custom-shipping' ), 
                'type'    => 'text', 
                'default' => __( 'Custom Delivery', 'custom-shipping' ) 
            ), 
            'cost' => array( 
                'title'   => __( 'Cost', 'custom-shipping' ), 
                'type'    => 'number', 
                'default' => 10, 
                'desc_tip' => true, 
                'description' => __( 'Flat cost for this shipping method.', 'custom-shipping' ) 
            ) 
        ); 
    } 
 
    public function calculate_shipping( $package = array() ) { 
        $rate = array( 
            'id'    => $this->get_rate_id(), 
            'label' => $this->title, 
            'cost'  => $this->cost 
        ); 
 
        $this->add_rate( $rate ); 
    } 
} 

Step 3: Activate & Configure 

– Go to extensions > Add New > Upload extension and upload your folder as a ZIP, or activate directly.

– Navigate to the WooCommerce platform > Settings > Delivery.

– Add or edit a Delivery Zone.

– Click Add delivery method → Select Custom Delivery.

– Click the method to set Title (e.g., “Standard Delivery”) and Cost (e.g., 12.99).

Best Practices and Security 

– Internationalization: Use __() and _e() for translatable strings.

– Performance: Cache API responses if possible.

– Security: Sanitize inputs, validate data from external sources.

– Updates: Handle the WooCommerce platform version compatibility; test with the latest releases.

– Documentation: Comment your code extensively for maintainability.

If your method involves sensitive data (e.g., API keys), store them securely using the WooCommerce platform settings or options.

Enhance WooCommerce Shipping with Custom Methods

The Way Forward

Creating a custom delivery method in the WooCommerce platform gives you full control over how delivery costs are calculated and displayed. Whether you’re building a simple flat rate or an advanced API-based delivery service, the WooCommerce platform’s flexible class structure makes it easy to extend.

With just a few lines of PHP, you can craft a fully functional delivery system tailored to your business logic without relying on third-party plugins.

Free Consultation

    Gaurang Jadav

    Dynamic and results-driven eCommerce leader with 17 years of experience in developing, managing, and scaling successful online businesses. Proven expertise in driving digital transformation, optimizing operations, and delivering exceptional customer experiences to enhance revenue growth and brand presence. A visionary strategist with a strong track record in leveraging cutting-edge technologies and omnichannel solutions to achieve competitive advantage in global markets.



    MAP_New

    Global Footprints

    Served clients across the globe from38+ countries

    iFlair Web Technologies
    Privacy Overview

    This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.