wc_normalize_postcode on tax and shipping postcode SAVE

This commit is contained in:
Mike Jolley 2016-06-06 16:17:15 +01:00
parent 437a627028
commit 1da23584f0
3 changed files with 6 additions and 10 deletions

View File

@ -348,6 +348,9 @@ class WC_Shipping_Zone extends WC_Data {
*/
public function add_location( $code, $type ) {
if ( $this->is_valid_location_type( $type ) ) {
if ( 'postcode' === $type ) {
$code = wc_normalize_postcode( $code );
}
$location = array(
'code' => wc_clean( $code ),
'type' => wc_clean( $type )

View File

@ -124,7 +124,7 @@ class WC_Shipping_Zones {
$country = strtoupper( wc_clean( $package['destination']['country'] ) );
$state = strtoupper( wc_clean( $package['destination']['state'] ) );
$continent = strtoupper( wc_clean( WC()->countries->get_continent_code_for_country( $country ) ) );
$postcode = strtoupper( wc_clean( $package['destination']['postcode'] ) );
$postcode = wc_normalize_postcode( wc_clean( $package['destination']['postcode'] ) );
$cache_key = WC_Cache_Helper::get_cache_prefix( 'shipping_zones' ) . 'wc_shipping_zone_' . md5( sprintf( '%s+%s+%s', $country, $state, $postcode ) );
$matching_zone_id = wp_cache_get( $cache_key, 'shipping_zones' );

View File

@ -233,7 +233,7 @@ class WC_Tax {
return array();
}
$postcode = wc_clean( $postcode );
$postcode = wc_normalize_postcode( wc_clean( $postcode ) );
$cache_key = WC_Cache_Helper::get_cache_prefix( 'taxes' ) . 'wc_tax_rates_' . md5( sprintf( '%s+%s+%s+%s+%s', $country, $state, $city, $postcode, $tax_class ) );
$matched_tax_rates = wp_cache_get( $cache_key, 'taxes' );
@ -812,14 +812,7 @@ class WC_Tax {
if ( ! is_array( $postcodes ) ) {
$postcodes = explode( ';', $postcodes );
}
$tax_rate = self::_get_tax_rate( $tax_rate_id );
$postcodes = array_diff( array_filter( $postcodes ), array( '*' ) );
foreach ( $postcodes as $key => $postcode ) {
$postcodes[ $key ] = wc_format_postcode( $postcode, $tax_rate['tax_rate_country'] );
}
self::_update_tax_rate_locations( $tax_rate_id, $postcodes, 'postcode' );
self::_update_tax_rate_locations( $tax_rate_id, array_diff( array_map( 'wc_normalize_postcode', array_filter( $postcodes ) ), array( '*' ) ), 'postcode' );
}
/**