WC_Tax::get_shipping_tax_rates()
Gets an array of matching shipping tax rates for a given class.
Метод класса: WC_Tax{}
Хуков нет.
Возвращает
Разное
.
Использование
$result = WC_Tax::get_shipping_tax_rates( $tax_class, $customer );
- $tax_class(строка)
- Tax class to get rates for.
По умолчанию: null - $customer(объект)
- Override the customer object to get their location.
По умолчанию: null
Код WC_Tax::get_shipping_tax_rates() WC Tax::get shipping tax rates WC 9.4.2
public static function get_shipping_tax_rates( $tax_class = null, $customer = null ) { // See if we have an explicitly set shipping tax class. $shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' ); if ( 'inherit' !== $shipping_tax_class ) { $tax_class = $shipping_tax_class; } $location = self::get_tax_location( $tax_class, $customer ); $matched_tax_rates = array(); if ( 4 === count( $location ) ) { list( $country, $state, $postcode, $city ) = $location; if ( ! is_null( $tax_class ) ) { // This will be per item shipping. $matched_tax_rates = self::find_shipping_rates( array( 'country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $tax_class, ) ); } elseif ( WC()->cart->get_cart() ) { // This will be per order shipping - loop through the order and find the highest tax class rate. $cart_tax_classes = WC()->cart->get_cart_item_tax_classes_for_shipping(); // No tax classes = no taxable items. if ( empty( $cart_tax_classes ) ) { return array(); } // If multiple classes are found, use the first one found unless a standard rate item is found. This will be the first listed in the 'additional tax class' section. if ( count( $cart_tax_classes ) > 1 && ! in_array( '', $cart_tax_classes, true ) ) { $tax_classes = self::get_tax_class_slugs(); foreach ( $tax_classes as $tax_class ) { if ( in_array( $tax_class, $cart_tax_classes, true ) ) { $matched_tax_rates = self::find_shipping_rates( array( 'country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $tax_class, ) ); break; } } } elseif ( 1 === count( $cart_tax_classes ) ) { // If a single tax class is found, use it. $matched_tax_rates = self::find_shipping_rates( array( 'country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $cart_tax_classes[0], ) ); } } // Get standard rate if no taxes were found. if ( ! count( $matched_tax_rates ) ) { $matched_tax_rates = self::find_shipping_rates( array( 'country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, ) ); } } return $matched_tax_rates; }