Automattic\WooCommerce\Blocks\Shipping

ShippingController::filter_shipping_packages()publicWC 1.0

Local Pickup requires all packages to support local pickup. This is because the entire order must be picked up so that all packages get the same tax rates applied during checkout.

If a shipping package does not support local pickup (e.g. if disabled by an extension), this filters the option out for all packages. This will in turn disable the "pickup" toggle in Block Checkout.

Method of the class: ShippingController{}

No Hooks.

Return

Array.

Usage

$ShippingController = new ShippingController();
$ShippingController->filter_shipping_packages( $packages );
$packages(array) (required)
Array of shipping packages.

ShippingController::filter_shipping_packages() code WC 9.2.3

public function filter_shipping_packages( $packages ) {
	// Check all packages for an instance of a collectable shipping method.
	$valid_packages = array_filter(
		$packages,
		function ( $package ) {
			$shipping_method_ids = ArrayUtil::select( $package['rates'] ?? array(), 'get_method_id', ArrayUtil::SELECT_BY_OBJECT_METHOD );
			return ! empty( array_intersect( LocalPickupUtils::get_local_pickup_method_ids(), $shipping_method_ids ) );
		}
	);

	// Remove pickup location from rates arrays.
	if ( count( $valid_packages ) !== count( $packages ) ) {
		$packages = array_map(
			function ( $package ) {
				if ( ! is_array( $package['rates'] ) ) {
					$package['rates'] = array();
					return $package;
				}
				$package['rates'] = array_filter(
					$package['rates'],
					function ( $rate ) {
						return ! in_array( $rate->get_method_id(), LocalPickupUtils::get_local_pickup_method_ids(), true );
					}
				);
				return $package;
			},
			$packages
		);
	}

	return $packages;
}