WC_Shipping_Legacy_Local_Delivery::calculate_shipping()publicWC 1.0

Calculate_shipping function.

Method of the class: WC_Shipping_Legacy_Local_Delivery{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Shipping_Legacy_Local_Delivery = new WC_Shipping_Legacy_Local_Delivery();
$WC_Shipping_Legacy_Local_Delivery->calculate_shipping( $package );
$package(array)
-
Default: array())

WC_Shipping_Legacy_Local_Delivery::calculate_shipping() code WC 8.7.0

public function calculate_shipping( $package = array() ) {
	$shipping_total = 0;

	switch ( $this->type ) {
		case 'fixed':
			$shipping_total = $this->fee;
			break;
		case 'percent':
			$shipping_total = $package['contents_cost'] * ( $this->fee / 100 );
			break;
		case 'product':
			foreach ( $package['contents'] as $item_id => $values ) {
				if ( $values['quantity'] > 0 && $values['data']->needs_shipping() ) {
					$shipping_total += $this->fee * $values['quantity'];
				}
			}
			break;
	}

	$rate = array(
		'id'      => $this->id,
		'label'   => $this->title,
		'cost'    => $shipping_total,
		'package' => $package,
	);

	$this->add_rate( $rate );
}