PHP Class WC_Shipping

Handles shipping and loads shipping methods via hooks.
Author: WooThemes
Exibir arquivo Open project: woocommerce/woocommerce Class Usage Examples

Public Properties

Property Type Description
$enabled True if shipping is enabled.
$packages Stores packages to ship and to get quotes for.
$shipping_classes Stores the shipping classes.
$shipping_methods Stores methods loaded into woocommerce.
$shipping_taxes Stores an array of shipping taxes.
$shipping_total Stores the cost of shipping

Protected Properties

Property Type Description
$_instance The single instance of the class

Public Methods

Method Description
__clone ( ) Cloning is forbidden.
__construct ( ) Initialize shipping.
__wakeup ( ) Unserializing instances of this class is forbidden.
calculate_shipping ( array $packages = [] ) Calculate shipping for (multiple) packages of cart items.
calculate_shipping_for_package ( array $package = [], integer $package_key ) : array 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 ( ) : array Returns all registered shipping methods for usage.
init ( ) Initialize shipping.
instance ( ) : WC_Shipping Main WC_Shipping Instance.
load_shipping_methods ( array $package = [] ) : array Loads all shipping methods which are hooked in. If a $package is passed some methods may add themselves conditionally.
register_shipping_method ( object | string $method ) Register a shipping method.
reset_shipping ( ) Reset shipping.
sort_shipping_methods ( )
unregister_shipping_methods ( ) Unregister shipping methods.

Protected Methods

Method Description
is_package_shippable ( array $package ) : boolean See if package is shippable.

Private Methods

Method Description
get_default_method ( array $available_methods, boolean $current_chosen_method = false ) : string Get the default method.

Method Details

__clone() public method

Cloning is forbidden.
Since: 2.1
public __clone ( )

__construct() public method

Initialize shipping.
public __construct ( )

__wakeup() public method

Unserializing instances of this class is forbidden.
Since: 2.1
public __wakeup ( )

calculate_shipping() public method

Calculate shipping for (multiple) packages of cart items.
public calculate_shipping ( array $packages = [] )
$packages array multi-dimensional array of cart items to calc shipping for

calculate_shipping_for_package() public method

Calculates each shipping methods cost. Rates are stored in the session based on the package hash to avoid re-calculation every page load.
public calculate_shipping_for_package ( array $package = [], integer $package_key ) : array
$package array cart items
$package_key integer Index of the package being calculated. Used to cache multiple package rates.
return array

get_packages() public method

Get packages.
public get_packages ( ) : array
return array

get_shipping_classes() public method

Get an array of shipping classes.
public get_shipping_classes ( ) : array
return array

get_shipping_method_class_names() public method

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

get_shipping_methods() public method

Returns all registered shipping methods for usage.
public get_shipping_methods ( ) : array
return array

init() public method

Initialize shipping.
public init ( )

instance() public static method

Ensures only one instance of WC_Shipping is loaded or can be loaded.
Since: 2.1
public static instance ( ) : WC_Shipping
return WC_Shipping Main instance

is_package_shippable() protected method

See if package is shippable.
protected is_package_shippable ( array $package ) : boolean
$package array
return boolean

load_shipping_methods() public method

Loads all shipping methods which are hooked in. If a $package is passed some methods may add themselves conditionally and zones will be used.
public load_shipping_methods ( array $package = [] ) : array
$package array
return array

register_shipping_method() public method

Register a shipping method.
public register_shipping_method ( object | string $method )
$method object | string Either the name of the method's class, or an instance of the method's class.

reset_shipping() public method

Reset the totals for shipping as a whole.
public reset_shipping ( )

sort_shipping_methods() public method

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

unregister_shipping_methods() public method

Unregister shipping methods.

Property Details

$_instance protected_oe static_oe property

The single instance of the class
Since: 2.1
protected static $_instance

$enabled public_oe property

True if shipping is enabled.
public $enabled

$packages public_oe property

Stores packages to ship and to get quotes for.
public $packages

$shipping_classes public_oe property

Stores the shipping classes.
public $shipping_classes

$shipping_methods public_oe property

Stores methods loaded into woocommerce.
public $shipping_methods

$shipping_taxes public_oe property

Stores an array of shipping taxes.
public $shipping_taxes

$shipping_total public_oe property

Stores the cost of shipping
public $shipping_total