Automattic\WooCommerce\Blocks\Shipping
ShippingController::filter_taxable_address
Filter the location used for taxes based on the chosen pickup location.
Метод класса: ShippingController{}
Хуки из метода
Возвращает
array.
Использование
$ShippingController = new ShippingController(); $ShippingController->filter_taxable_address( $address );
- $address(массив) (обязательный)
- Location args.
Код ShippingController::filter_taxable_address() ShippingController::filter taxable address WC 11.2.2
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.
// The first entry is used only when its rate was listed for the cart.
$chosen_methods = WC()->session->get( 'chosen_shipping_methods', array() );
$first_key = is_array( $chosen_methods ) && ! empty( $chosen_methods ) ? array_key_first( $chosen_methods ) : null;
$listed_methods = null !== $first_key ? ShippingUtil::filter_chosen_shipping_methods( $chosen_methods ) : array();
$chosen_method = null !== $first_key && isset( $listed_methods[ $first_key ] ) ? (string) $listed_methods[ $first_key ] : '';
$chosen_method_id = explode( ':', $chosen_method )[0];
$chosen_method_instance = explode( ':', $chosen_method )[1] ?? 0;
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- Documented in WC_Abstract_Order::get_tax_location().
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', array() );
$pickup_location = $pickup_locations[ $chosen_method_instance ] ?? array();
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;
}