PHP Class WC_Shipping_Method

Extended by shipping methods to handle shipping calculations etc.
Author: WooThemes
Inheritance: extends WC_Settings_API
Show file Open project: woocommerce/woocommerce Class Usage Examples

Public Properties

Property Type Description
$availability string No longer useful for instance based shipping methods.
$countries array No longer useful for instance based shipping methods.
$enabled string yes or no based on whether the method is enabled.
$fee string Fee for the method (if applicable).
$id string Unique ID for the shipping method - must be set.
$instance_form_fields array Instance form fields.
$instance_id integer Instance ID if used.
$instance_settings array Instance settings.
$method_description string Method description.
$method_title string Method title.
$minimum_fee string Minimum fee for the method (if applicable).
$rates array This is an array of rates - methods must populate this array to register shipping costs.
$supports array - settings Non-instance settings screens. Enabled by default for BW compatibility with methods before instances existed. - instance-settings-modal Allows the instance settings to be loaded within a modal in the zones UI.
$tax_status string If 'taxable' tax will be charged for this method (if applicable).
$title string Shipping method title for the frontend.

Public Methods

Method Description
__construct ( integer $instance_id ) Constructor.
add_rate ( array $args = [] ) Add a shipping rate. If taxes are not set they will be calculated based on cost.
admin_options ( ) Output the shipping settings screen.
calculate_shipping ( $package = [] ) Called to calculate shipping rates for this method. Rates can be added using the add_rate() method.
get_admin_options_html ( ) : string Return admin options as a html string.
get_fee ( string | float $fee, float $total ) : float Get fee to add to shipping cost.
get_instance_form_fields ( ) : array Get settings fields for instances of this shipping method (within zones).
get_instance_id ( ) : integer Return the shipping method instance ID.
get_instance_option ( string $key, mixed $empty_value = null ) : mixed Gets an option from the settings API, using defaults if necessary to prevent undefined notices.
get_instance_option_key ( ) : string Return the name of the option in the WP DB.
get_method_description ( ) : string Return the shipping method description.
get_method_title ( ) : string Return the shipping method title.
get_option ( string $key, mixed $empty_value = null ) : mixed get_option function.
get_rate_id ( string $suffix = '' ) : string Returns a rate ID based on this methods ID and instance, with an optional suffix if distinguishing between multiple rates.
get_rates_for_package ( object $package ) : array Return calculated rates for a package.
get_title ( ) : string Return the shipping title which is user set.
has_settings ( ) : boolean Does this method have a settings page?
init_instance_settings ( ) Initialise Settings for instances.
is_available ( array $package ) : boolean Is this method available?
is_enabled ( ) : boolean Whether or not this method is enabled in settings.
is_taxable ( ) : boolean Whether or not we need to calculate tax on top of the shipping rate.
process_admin_options ( ) : boolean Processes and saves options.
supports ( $feature ) : boolean Check if a shipping method supports a given feature.

Protected Methods

Method Description
get_taxes_per_item ( array $costs ) : array Calc taxes per item being shipping in costs array.

Method Details

__construct() public method

Constructor.
public __construct ( integer $instance_id )
$instance_id integer

add_rate() public method

Add a shipping rate. If taxes are not set they will be calculated based on cost.
public add_rate ( array $args = [] )
$args array (default: array())

admin_options() public method

Output the shipping settings screen.
public admin_options ( )

calculate_shipping() public method

Called to calculate shipping rates for this method. Rates can be added using the add_rate() method.
public calculate_shipping ( $package = [] )

get_admin_options_html() public method

Return admin options as a html string.
public get_admin_options_html ( ) : string
return string

get_fee() public method

Get fee to add to shipping cost.
public get_fee ( string | float $fee, float $total ) : float
$fee string | float
$total float
return float

get_instance_form_fields() public method

Should be overridden by shipping methods to add options.
Since: 2.6.0
public get_instance_form_fields ( ) : array
return array

get_instance_id() public method

Return the shipping method instance ID.
Since: 2.6.0
public get_instance_id ( ) : integer
return integer

get_instance_option() public method

Gets an option from the settings API, using defaults if necessary to prevent undefined notices.
public get_instance_option ( string $key, mixed $empty_value = null ) : mixed
$key string
$empty_value mixed
return mixed The value specified for the option or a default value for the option.

get_instance_option_key() public method

Return the name of the option in the WP DB.
Since: 2.6.0
public get_instance_option_key ( ) : string
return string

get_method_description() public method

Return the shipping method description.
Since: 2.6.0
public get_method_description ( ) : string
return string

get_method_title() public method

Return the shipping method title.
Since: 2.6.0
public get_method_title ( ) : string
return string

get_option() public method

Gets and option from the settings API, using defaults if necessary to prevent undefined notices.
public get_option ( string $key, mixed $empty_value = null ) : mixed
$key string
$empty_value mixed
return mixed The value specified for the option or a default value for the option.

get_rate_id() public method

Returns a rate ID based on this methods ID and instance, with an optional suffix if distinguishing between multiple rates.
Since: 2.6.0
public get_rate_id ( string $suffix = '' ) : string
$suffix string
return string

get_rates_for_package() public method

Return calculated rates for a package.
Since: 2.6.0
public get_rates_for_package ( object $package ) : array
$package object
return array

get_taxes_per_item() protected method

Calc taxes per item being shipping in costs array.
Since: 2.6.0
protected get_taxes_per_item ( array $costs ) : array
$costs array
return array of taxes

get_title() public method

Return the shipping title which is user set.
public get_title ( ) : string
return string

has_settings() public method

Does this method have a settings page?
public has_settings ( ) : boolean
return boolean

init_instance_settings() public method

Initialise Settings for instances.
Since: 2.6.0

is_available() public method

Is this method available?
public is_available ( array $package ) : boolean
$package array
return boolean

is_enabled() public method

Whether or not this method is enabled in settings.
Since: 2.6.0
public is_enabled ( ) : boolean
return boolean

is_taxable() public method

Whether or not we need to calculate tax on top of the shipping rate.
public is_taxable ( ) : boolean
return boolean

process_admin_options() public method

If there is an error thrown, will continue to save and validate fields, but will leave the erroring field out.
Since: 2.6.0
public process_admin_options ( ) : boolean
return boolean was anything saved?

supports() public method

Methods should override this to declare support (or lack of support) for a feature.
public supports ( $feature ) : boolean
$feature string The name of a feature to test support for.
return boolean True if the shipping method supports the feature, false otherwise.

Property Details

$availability public property

No longer useful for instance based shipping methods.
Deprecation: 2.6.0
public string $availability
return string

$countries public property

No longer useful for instance based shipping methods.
Deprecation: 2.6.0
public array $countries
return array

$enabled public property

yes or no based on whether the method is enabled.
public string $enabled
return string

$fee public property

Fee for the method (if applicable).
public string $fee
return string

$id public property

Unique ID for the shipping method - must be set.
public string $id
return string

$instance_form_fields public property

Instance form fields.
public array $instance_form_fields
return array

$instance_id public property

Instance ID if used.
public int $instance_id
return integer

$instance_settings public property

Instance settings.
public array $instance_settings
return array

$method_description public property

Method description.
public string $method_description
return string

$method_title public property

Method title.
public string $method_title
return string

$minimum_fee public property

Minimum fee for the method (if applicable).
public string $minimum_fee
return string

$rates public property

This is an array of rates - methods must populate this array to register shipping costs.
public array $rates
return array

$supports public property

- settings Non-instance settings screens. Enabled by default for BW compatibility with methods before instances existed. - instance-settings-modal Allows the instance settings to be loaded within a modal in the zones UI.
public array $supports
return array

$tax_status public property

If 'taxable' tax will be charged for this method (if applicable).
public string $tax_status
return string

$title public property

Shipping method title for the frontend.
public string $title
return string