WC_Abstract_Order::get_tax_location()protectedWC 3.2.0

Get tax location for this order.

{} Это метод класса: WC_Abstract_Order{}

Возвращает

Массив.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_tax_location( $args );
$args(массив)
array Override the location.
По умолчанию: array()

Список изменений

С версии 3.2.0 Введена.

Код WC_Abstract_Order::get_tax_location() WC 6.9.4

protected function get_tax_location( $args = array() ) {
	$tax_based_on = get_option( 'woocommerce_tax_based_on' );

	if ( 'shipping' === $tax_based_on && ! $this->get_shipping_country() ) {
		$tax_based_on = 'billing';
	}

	$args = wp_parse_args(
		$args,
		array(
			'country'  => 'billing' === $tax_based_on ? $this->get_billing_country() : $this->get_shipping_country(),
			'state'    => 'billing' === $tax_based_on ? $this->get_billing_state() : $this->get_shipping_state(),
			'postcode' => 'billing' === $tax_based_on ? $this->get_billing_postcode() : $this->get_shipping_postcode(),
			'city'     => 'billing' === $tax_based_on ? $this->get_billing_city() : $this->get_shipping_city(),
		)
	);

	/**
	 * Filters whether apply base tax for local pickup shipping method or not.
	 *
	 * @since 6.8.0
	 * @param boolean apply_base_tax Whether apply base tax for local pickup. Default true.
	 */
	$apply_base_tax = true === apply_filters( 'woocommerce_apply_base_tax_for_local_pickup', true );

	/**
	 * Filters local pickup shipping methods.
	 *
	 * @since 6.8.0
	 * @param string[] $local_pickup_methods Local pickup shipping method IDs.
	 */
	$local_pickup_methods = apply_filters( 'woocommerce_local_pickup_methods', array( 'legacy_local_pickup', 'local_pickup' ) );

	$shipping_method_ids = ArrayUtil::select( $this->get_shipping_methods(), 'get_method_id', ArrayUtil::SELECT_BY_OBJECT_METHOD );

	// Set shop base address as a tax location if order has local pickup shipping method.
	if ( $apply_base_tax && count( array_intersect( $shipping_method_ids, $local_pickup_methods ) ) > 0 ) {
		$tax_based_on = 'base';
	}

	// Default to base.
	if ( 'base' === $tax_based_on || empty( $args['country'] ) ) {
		$args['country']  = WC()->countries->get_base_country();
		$args['state']    = WC()->countries->get_base_state();
		$args['postcode'] = WC()->countries->get_base_postcode();
		$args['city']     = WC()->countries->get_base_city();
	}

	return apply_filters( 'woocommerce_order_get_tax_location', $args, $this );
}