Code Duplication    Length = 26-34 lines in 2 locations

includes/class-wc-ajax.php 1 location

@@ 1583-1608 (lines=26) @@
1580
				$order_item_tax_classes = array_unique( array_values( $order_item_tax_classes ) );
1581
1582
				// If multiple classes are found, use the first one. Don't bother with standard rate, we can get that later.
1583
				if ( sizeof( $order_item_tax_classes ) > 1 && ! in_array( '', $order_item_tax_classes ) ) {
1584
					$tax_classes = WC_Tax::get_tax_classes();
1585
1586
					foreach ( $tax_classes as $tax_class ) {
1587
						$tax_class = sanitize_title( $tax_class );
1588
						if ( in_array( $tax_class, $order_item_tax_classes ) ) {
1589
							$matched_tax_rates = WC_Tax::find_shipping_rates( array(
1590
								'country' 	=> $country,
1591
								'state' 	=> $state,
1592
								'postcode' 	=> $postcode,
1593
								'city' 		=> $city,
1594
								'tax_class' => $tax_class,
1595
							) );
1596
							break;
1597
						}
1598
					}
1599
				// If a single tax class is found, use it
1600
				} elseif ( sizeof( $order_item_tax_classes ) === 1 ) {
1601
					$matched_tax_rates = WC_Tax::find_shipping_rates( array(
1602
						'country' 	=> $country,
1603
						'state' 	=> $state,
1604
						'postcode' 	=> $postcode,
1605
						'city' 		=> $city,
1606
						'tax_class' => $order_item_tax_classes[0]
1607
					) );
1608
				}
1609
1610
				// Get standard rate if no taxes were found
1611
				if ( ! sizeof( $matched_tax_rates ) ) {

includes/class-wc-tax.php 1 location

@@ 464-497 (lines=34) @@
461
					'tax_class' => $tax_class
462
				) );
463
464
			} else {
465
466
				// This will be per order shipping - loop through the order and find the highest tax class rate
467
				$cart_tax_classes = WC()->cart->get_cart_item_tax_classes();
468
469
				// If multiple classes are found, use the first one. Don't bother with standard rate, we can get that later.
470
				if ( sizeof( $cart_tax_classes ) > 1 && ! in_array( '', $cart_tax_classes ) ) {
471
					$tax_classes = self::get_tax_classes();
472
473
					foreach ( $tax_classes as $tax_class ) {
474
						$tax_class = sanitize_title( $tax_class );
475
						if ( in_array( $tax_class, $cart_tax_classes ) ) {
476
							$matched_tax_rates = self::find_shipping_rates( array(
477
								'country' 	=> $country,
478
								'state' 	=> $state,
479
								'postcode' 	=> $postcode,
480
								'city' 		=> $city,
481
								'tax_class' => $tax_class
482
							) );
483
							break;
484
						}
485
					}
486
487
				// If a single tax class is found, use it
488
				} elseif ( sizeof( $cart_tax_classes ) == 1 ) {
489
					$matched_tax_rates = self::find_shipping_rates( array(
490
						'country' 	=> $country,
491
						'state' 	=> $state,
492
						'postcode' 	=> $postcode,
493
						'city' 		=> $city,
494
						'tax_class' => $cart_tax_classes[0]
495
					) );
496
				}
497
			}
498
499
			// Get standard rate if no taxes were found
500
			if ( ! sizeof( $matched_tax_rates ) ) {