Automattic\WooCommerce\Blocks\Shipping

PickupLocation::calculate_shippingpublicWC 1.0

Calculate shipping.

Method of the class: PickupLocation{}

No Hooks.

Returns

null. Nothing (null).

Usage

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

PickupLocation::calculate_shipping() code WC 11.0.1

public function calculate_shipping( $package = array() ) {
	if ( $this->pickup_locations ) {
		foreach ( $this->pickup_locations as $index => $location ) {
			if ( ! $location['enabled'] ) {
				continue;
			}
			$has_valid_address = $this->has_valid_pickup_location( $location['address'] );
			$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,
					// `_pickup_location_address` is hidden (underscore-prefixed) structured address data, captured at
					// purchase time, used to derive the order tax location. See ShippingController::filter_order_tax_location().
					'meta_data' => array(
						'pickup_location'          => wp_kses_post( $location['name'] ),
						'pickup_address'           => $has_valid_address ? wc()->countries->get_formatted_address( $location['address'], ', ' ) : '',
						'pickup_details'           => wp_kses_post( $location['details'] ),
						'_pickup_location_address' => $has_valid_address ? $location['address'] : array(),
					),
				)
			);
		}
	}
}