WooCommerce Code Reference

WC_Shipping

Shipping class.

Table of Contents

$enabled  : bool
True if shipping is enabled.
$packages  : array
Stores packages to ship and to get quotes for.
$shipping_classes  : array
Stores the shipping classes.
$shipping_methods  : array|null
Stores methods loaded into woocommerce.
$_instance  : WC_Shipping
The single instance of the class
__clone()  : mixed
Cloning is forbidden.
__construct()  : mixed
Initialize shipping.
__get()  : mixed
Magic getter.
__wakeup()  : mixed
Unserializing instances of this class is forbidden.
calculate_shipping()  : array
Calculate shipping for (multiple) packages of cart items.
calculate_shipping_for_package()  : array|bool
Calculate shipping rates for a package,
get_packages()  : array
Get packages.
get_shipping_classes()  : array
Get an array of shipping classes.
get_shipping_method_class_names()  : array
Shipping methods register themselves by returning their main class name through the woocommerce_shipping_methods filter.
get_shipping_methods()  : \WC_Shipping_Method[]
Returns all registered shipping methods for usage.
init()  : mixed
Initialize shipping.
instance()  : WC_Shipping
Main WC_Shipping Instance.
is_package_shippable()  : bool
See if package is shippable.
load_shipping_methods()  : \WC_Shipping_Method[]
Loads all shipping methods which are hooked in.
register_shipping_method()  : bool|void
Register a shipping method.
reset_shipping()  : mixed
Reset shipping.
sort_shipping_methods()  : mixed
Deprecated
unregister_shipping_methods()  : mixed
Unregister shipping methods.

Properties

Methods

__get()

Magic getter.

public __get(string $name) : mixed
Parameters
$name : string

Property name.

Return values
mixed

__wakeup()

Unserializing instances of this class is forbidden.

public __wakeup() : mixed
Tags
since
2.1
Return values
mixed

calculate_shipping()

Calculate shipping for (multiple) packages of cart items.

public calculate_shipping([array $packages = array() ]) : array
Parameters
$packages : array = array()

multi-dimensional array of cart items to calc shipping for.

Return values
arrayArray of calculated packages.

calculate_shipping_for_package()

Calculate shipping rates for a package,

public calculate_shipping_for_package([array $package = array() ], int $package_key) : array|bool

Calculates each shipping methods cost. Rates are stored in the session based on the package hash to avoid re-calculation every page load.

Parameters
$package : array = array()

Package of cart items.

$package_key : int

Index of the package being calculated. Used to cache multiple package rates.

Return values
array|bool

get_shipping_classes()

Get an array of shipping classes.

public get_shipping_classes() : array
Return values
array

get_shipping_method_class_names()

Shipping methods register themselves by returning their main class name through the woocommerce_shipping_methods filter.

public get_shipping_method_class_names() : array
Return values
array

get_shipping_methods()

Returns all registered shipping methods for usage.

public get_shipping_methods() : \WC_Shipping_Method[]
Return values
\WC_Shipping_Method[]

is_package_shippable()

See if package is shippable.

public is_package_shippable(array $package) : bool

Packages are shippable until proven otherwise e.g. after getting a shipping country.

Parameters
$package : array

Package of cart items.

Return values
bool

load_shipping_methods()

Loads all shipping methods which are hooked in.

public load_shipping_methods([array $package = array() ]) : \WC_Shipping_Method[]

If a $package is passed some methods may add themselves conditionally and zones will be used.

Parameters
$package : array = array()

Package information.

Return values
\WC_Shipping_Method[]

register_shipping_method()

Register a shipping method.

public register_shipping_method(object|string $method) : bool|void
Parameters
$method : object|string

Either the name of the method's class, or an instance of the method's class.

Return values
bool|void

reset_shipping()

Reset shipping.

public reset_shipping() : mixed

Reset the totals for shipping as a whole.

Return values
mixed

sort_shipping_methods()

Deprecated

public sort_shipping_methods() : mixed
Tags
deprecated
2.6.0

Was previously used to determine sort order of methods, but this is now controlled by zones and thus unused.

Return values
mixed

unregister_shipping_methods()

Unregister shipping methods.

public unregister_shipping_methods() : mixed
Return values
mixed