Automattic\WooCommerce\Blocks\Shipping

PickupLocation::calculate_shipping()publicWC 1.0

Calculate shipping.

Method of the class: PickupLocation{}

No Hooks.

Return

null. Nothing (null).

Usage

$PickupLocation = new PickupLocation();
$PickupLocation->calculate_shipping( $package );
$package(array)
Package information.
Default: array()

PickupLocation::calculate_shipping() code WC 9.8.1

public function calculate_shipping( $package = array() ) {
	if ( $this->pickup_locations ) {
		foreach ( $this->pickup_locations as $index => $location ) {
			if ( ! $location['enabled'] ) {
				continue;
			}
			$this->add_rate(
				array(
					'id'        => $this->id . ':' . $index,
					// This is the label shown in shipping rate/method context e.g. London (Local Pickup).
					'label'     => wp_kses_post( $this->title . ' (' . $location['name'] . ')' ),
					'package'   => $package,
					'cost'      => $this->cost,
					'meta_data' => array(
						'pickup_location' => wp_kses_post( $location['name'] ),
						'pickup_address'  => $this->has_valid_pickup_location( $location['address'] ) ? wc()->countries->get_formatted_address( $location['address'], ', ' ) : '',
						'pickup_details'  => wp_kses_post( $location['details'] ),
					),
				)
			);
		}
	}
}