Skip to content

Commit

Permalink
Merge pull request #121 from dallendalton/PI-225-Tax-Rate-Space-Fix
Browse files Browse the repository at this point in the history
Tax Rate Lookup State Containing Space Fix
  • Loading branch information
dallendalton authored Aug 12, 2019
2 parents 485569c + 37bc432 commit 130d75a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions includes/class-wc-taxjar-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,19 @@ public function create_or_update_tax_rate( $location, $rate, $tax_class = '', $f
'tax_rate_class' => $tax_class,
);

$wc_rate = WC_Tax::find_rates( array(
$rate_lookup = array(
'country' => $location['to_country'],
'state' => $location['to_state'],
'postcode' => $location['to_zip'],
'city' => $location['to_city'],
'tax_class' => $tax_class,
) );
);

if ( version_compare( WC()->version, '3.2.0', '>=' ) ) {
$rate_lookup['state'] = sanitize_key( $location['to_state'] );
}

$wc_rate = WC_Tax::find_rates( $rate_lookup );

if ( ! empty( $wc_rate ) ) {
$this->_log( ':: Tax Rate Found ::' );
Expand Down
13 changes: 13 additions & 0 deletions tests/specs/test-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1070,4 +1070,17 @@ function test_vat_exempt_customer_with_shipping() {
WC()->session->set( 'chosen_shipping_methods', array() );
TaxJar_Shipping_Helper::delete_simple_flat_rate();
}

function test_tax_lookup_state_with_space() {
$location = array(
'to_country' => 'GB',
'to_state' => 'West Sussex',
'to_zip' => 'BN15 1S2',
'to_city' => 'London'
);
$rate_id = $this->tj->create_or_update_tax_rate( $location, 10 );
$found_rate_id = $this->tj->create_or_update_tax_rate( $location, 10 );

$this->assertEquals( $rate_id, $found_rate_id );
}
}

0 comments on commit 130d75a

Please sign in to comment.