| @@ 516-549 (lines=34) @@ | ||
| 513 | 'tax_class' => $tax_class |
|
| 514 | ) ); |
|
| 515 | ||
| 516 | } else { |
|
| 517 | ||
| 518 | // This will be per order shipping - loop through the order and find the highest tax class rate |
|
| 519 | $cart_tax_classes = WC()->cart->get_cart_item_tax_classes(); |
|
| 520 | ||
| 521 | // If multiple classes are found, use the first one. Don't bother with standard rate, we can get that later. |
|
| 522 | if ( sizeof( $cart_tax_classes ) > 1 && ! in_array( '', $cart_tax_classes ) ) { |
|
| 523 | $tax_classes = self::get_tax_classes(); |
|
| 524 | ||
| 525 | foreach ( $tax_classes as $tax_class ) { |
|
| 526 | $tax_class = sanitize_title( $tax_class ); |
|
| 527 | if ( in_array( $tax_class, $cart_tax_classes ) ) { |
|
| 528 | $matched_tax_rates = self::find_shipping_rates( array( |
|
| 529 | 'country' => $country, |
|
| 530 | 'state' => $state, |
|
| 531 | 'postcode' => $postcode, |
|
| 532 | 'city' => $city, |
|
| 533 | 'tax_class' => $tax_class |
|
| 534 | ) ); |
|
| 535 | break; |
|
| 536 | } |
|
| 537 | } |
|
| 538 | ||
| 539 | // If a single tax class is found, use it |
|
| 540 | } elseif ( sizeof( $cart_tax_classes ) == 1 ) { |
|
| 541 | $matched_tax_rates = self::find_shipping_rates( array( |
|
| 542 | 'country' => $country, |
|
| 543 | 'state' => $state, |
|
| 544 | 'postcode' => $postcode, |
|
| 545 | 'city' => $city, |
|
| 546 | 'tax_class' => $cart_tax_classes[0] |
|
| 547 | ) ); |
|
| 548 | } |
|
| 549 | } |
|
| 550 | ||
| 551 | // Get standard rate if no taxes were found |
|
| 552 | if ( ! sizeof( $matched_tax_rates ) ) { |
|
| @@ 1499-1524 (lines=26) @@ | ||
| 1496 | $order_item_tax_classes = array_unique( array_values( $order_item_tax_classes ) ); |
|
| 1497 | ||
| 1498 | // If multiple classes are found, use the first one. Don't bother with standard rate, we can get that later. |
|
| 1499 | if ( sizeof( $order_item_tax_classes ) > 1 && ! in_array( '', $order_item_tax_classes ) ) { |
|
| 1500 | $tax_classes = WC_Tax::get_tax_classes(); |
|
| 1501 | ||
| 1502 | foreach ( $tax_classes as $tax_class ) { |
|
| 1503 | $tax_class = sanitize_title( $tax_class ); |
|
| 1504 | if ( in_array( $tax_class, $order_item_tax_classes ) ) { |
|
| 1505 | $matched_tax_rates = WC_Tax::find_shipping_rates( array( |
|
| 1506 | 'country' => $country, |
|
| 1507 | 'state' => $state, |
|
| 1508 | 'postcode' => $postcode, |
|
| 1509 | 'city' => $city, |
|
| 1510 | 'tax_class' => $tax_class, |
|
| 1511 | ) ); |
|
| 1512 | break; |
|
| 1513 | } |
|
| 1514 | } |
|
| 1515 | // If a single tax class is found, use it |
|
| 1516 | } elseif ( sizeof( $order_item_tax_classes ) === 1 ) { |
|
| 1517 | $matched_tax_rates = WC_Tax::find_shipping_rates( array( |
|
| 1518 | 'country' => $country, |
|
| 1519 | 'state' => $state, |
|
| 1520 | 'postcode' => $postcode, |
|
| 1521 | 'city' => $city, |
|
| 1522 | 'tax_class' => $order_item_tax_classes[0] |
|
| 1523 | ) ); |
|
| 1524 | } |
|
| 1525 | ||
| 1526 | // Get standard rate if no taxes were found |
|
| 1527 | if ( ! sizeof( $matched_tax_rates ) ) { |
|