Local for Local Development
I highly recommend Local for developing WordPress sites on your development PC. Easy as 1, 2, 3 and you up and running with the latest WP setup.
WooCommerce Custom Shipping Method Plugin
Create your own shipping method.
WordPress
Plugin Handbook
WooCommerce
WooCommerce Handbook
Setting up your plugin
Creating the folders
In your WordPress installation, go to wp-content > plugins, create a folder called woocommerce-custom-shipping-method.
The main PHP file
In this new folder simple-plugin, create a file called woocommerce-custom-shipping-method.php
The main PHP file
Copy and paste the below code into your new woocommerce-custom-shipping-method.php
wp-content
└── plugins
└── woocommerce-custom-shipping-method
└── woocommerce-custom-shipping-method.php
id = 'custom_shipping';
$this->method_title = __('Custom Shipping Method', 'woocommerce-custom-shipping-method');
$this->method_description = __('This is a custom shipping method', 'woocommerce-custom-shipping-method');
$this->method_order = 10;
$this->enabled = "yes";
$this->title = "Custom Shipping Method";
$this->init();
}
public function init()
{
$this->init_form_fields();
$this->init_settings();
add_action('woocommerce_update_options_shipping' . $this->id, array($this, 'process_admin_options'));
}
public function calculate_shipping($package = array())
{
$rate = array(
'label' => $this->title,
'cost' => '120',
'calc_tax' => 'per_item',
);
$this->add_rate($rate);
}
}
}
}
add_filter('woocommerce_shipping_methods', 'add_custom_shipping_method');
function add_custom_shipping_method($methods)
{
$methods['custom_shipping_method'] = 'WC_CUSTOM_SHIPPING';
return $methods;
}
Take note of the various sections above, make sure to update the information to correlate to your personal / company information.
The above plugin creates a very basic set rate for shipping. Adjust and add to the init and calculculate_shipping functions as needed.
Add comment