Automattic\WooCommerce\Blocks\Shipping

ShippingController::filter_taxable_address()publicWC 1.0

Filter the location used for taxes based on the chosen pickup location.

Метод класса: ShippingController{}

Хуки из метода

Возвращает

Массив.

Использование

$ShippingController = new ShippingController();
$ShippingController->filter_taxable_address( $address );
$address(массив) (обязательный)
Location args.

Код ShippingController::filter_taxable_address() WC 8.7.0

public function filter_taxable_address( $address ) {

	if ( null === WC()->session ) {
		return $address;
	}
	// We only need to select from the first package, since pickup_location only supports a single package.
	$chosen_method          = current( WC()->session->get( 'chosen_shipping_methods', array() ) ) ?? '';
	$chosen_method_id       = explode( ':', $chosen_method )[0];
	$chosen_method_instance = explode( ':', $chosen_method )[1] ?? 0;

	// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
	if ( $chosen_method_id && true === apply_filters( 'woocommerce_apply_base_tax_for_local_pickup', true ) && in_array( $chosen_method_id, LocalPickupUtils::get_local_pickup_method_ids(), true ) ) {
		$pickup_locations = get_option( 'pickup_location_pickup_locations', [] );
		$pickup_location  = $pickup_locations[ $chosen_method_instance ] ?? [];

		if ( isset( $pickup_location['address'], $pickup_location['address']['country'] ) && ! empty( $pickup_location['address']['country'] ) ) {
			$address = array(
				$pickup_locations[ $chosen_method_instance ]['address']['country'],
				$pickup_locations[ $chosen_method_instance ]['address']['state'],
				$pickup_locations[ $chosen_method_instance ]['address']['postcode'],
				$pickup_locations[ $chosen_method_instance ]['address']['city'],
			);
		}
	}

	return $address;
}