See here for available alpha-2 country codes.', 'woocommerce' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?>

get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_class = %s ORDER BY tax_rate_order " , sanitize_title( $current_class ) ) ); foreach ( $rates as $rate ) { ?>
   [?]  [?]  [?]  [?]  [?]  [?]  [?]  [?]  [?]
prefix}woocommerce_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) ); echo esc_attr( implode( '; ', $locations ) ); ?>" placeholder="*" data-name="tax_rate_postcode[tax_rate_id ?>]" /> prefix}woocommerce_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) ); echo esc_attr( implode( '; ', $locations ) ); ?>" placeholder="*" data-name="tax_rate_city[tax_rate_id ?>]" /> tax_rate_compound, '1' ); ?> /> tax_rate_shipping, '1' ); ?> />
$value ) { // new keys are inserted... if ( $key == 'new' ) { foreach ( $value as $new_key => $new_value ) { // Sanitize + format $country = strtoupper( woocommerce_clean( $tax_rate_country[ $key ][ $new_key ] ) ); $state = strtoupper( woocommerce_clean( $tax_rate_state[ $key ][ $new_key ] ) ); $postcode = woocommerce_clean( $tax_rate_postcode[ $key ][ $new_key ] ); $city = woocommerce_clean( $tax_rate_city[ $key ][ $new_key ] ); $rate = number_format( woocommerce_clean( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' ); $name = woocommerce_clean( $tax_rate_name[ $key ][ $new_key ] ); $priority = absint( woocommerce_clean( $tax_rate_priority[ $key ][ $new_key ] ) ); $compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0; $shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0; if ( ! $name ) $name = __( 'Tax', 'woocommerce' ); if ( $country == '*' ) $country = ''; if ( $state == '*' ) $state = ''; $wpdb->insert( $wpdb->prefix . "woocommerce_tax_rates", array( 'tax_rate_country' => $country, 'tax_rate_state' => $state, 'tax_rate' => $rate, 'tax_rate_name' => $name, 'tax_rate_priority' => $priority, 'tax_rate_compound' => $compound, 'tax_rate_shipping' => $shipping, 'tax_rate_order' => $i, 'tax_rate_class' => sanitize_title( $current_class ) ) ); $tax_rate_id = $wpdb->insert_id; if ( ! empty( $postcode ) ) { $postcodes = explode( ';', $postcode ); $postcodes = array_map( 'strtoupper', array_map( 'woocommerce_clean', $postcodes ) ); $postcode_query = array(); foreach( $postcodes as $postcode ) if ( strstr( $postcode, '-' ) ) { $postcode_parts = explode( '-', $postcode ); if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) { for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) { if ( $i ) $postcode_query[] = "( '$i', $tax_rate_id, 'postcode' )"; } } } else { if ( $postcode ) $postcode_query[] = "( '$postcode', $tax_rate_id, 'postcode' )"; } $wpdb->query( "INSERT INTO {$wpdb->prefix}woocommerce_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) ); } if ( ! empty( $city ) ) { $cities = explode( ';', $city ); $cities = array_map( 'strtoupper', array_map( 'woocommerce_clean', $cities ) ); foreach( $cities as $city ) { $wpdb->insert( $wpdb->prefix . "woocommerce_tax_rate_locations", array( 'location_code' => $city, 'tax_rate_id' => $tax_rate_id, 'location_type' => 'city', ) ); } } $i++; } // ...whereas the others are updated } else { $tax_rate_id = absint( $key ); if ( $_POST['remove_tax_rate'][ $key ] == 1 ) { $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) ); continue; } // Sanitize + format $country = strtoupper( woocommerce_clean( $tax_rate_country[ $key ] ) ); $state = strtoupper( woocommerce_clean( $tax_rate_state[ $key ] ) ); $rate = number_format( woocommerce_clean( $tax_rate[ $key ] ), 4, '.', '' ); $name = woocommerce_clean( $tax_rate_name[ $key ] ); $priority = absint( woocommerce_clean( $tax_rate_priority[ $key ] ) ); $compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0; $shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0; if ( ! $name ) $name = __( 'Tax', 'woocommerce' ); if ( $country == '*' ) $country = ''; if ( $state == '*' ) $state = ''; $wpdb->update( $wpdb->prefix . "woocommerce_tax_rates", array( 'tax_rate_country' => $country, 'tax_rate_state' => $state, 'tax_rate' => $rate, 'tax_rate_name' => $name, 'tax_rate_priority' => $priority, 'tax_rate_compound' => $compound, 'tax_rate_shipping' => $shipping, 'tax_rate_order' => $i, 'tax_rate_class' => sanitize_title( $current_class ) ), array( 'tax_rate_id' => $tax_rate_id ) ); if ( isset( $tax_rate_postcode[ $key ] ) ) { // Delete old $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) ); // Add changed $postcode = woocommerce_clean( $tax_rate_postcode[ $key ] ); $postcodes = explode( ';', $postcode ); $postcodes = array_map( 'strtoupper', array_map( 'woocommerce_clean', $postcodes ) ); $postcode_query = array(); foreach( $postcodes as $postcode ) if ( strstr( $postcode, '-' ) ) { $postcode_parts = explode( '-', $postcode ); if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) { for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) { if ( $i ) $postcode_query[] = "( '$i', $tax_rate_id, 'postcode' )"; } } } else { if ( $postcode ) $postcode_query[] = "( '$postcode', $tax_rate_id, 'postcode' )"; } $wpdb->query( "INSERT INTO {$wpdb->prefix}woocommerce_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) ); } if ( isset( $tax_rate_city[ $key ] ) ) { // Delete old $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) ); // Add changed $city = woocommerce_clean( $tax_rate_city[ $key ] ); $cities = explode( ';', $city ); $cities = array_map( 'strtoupper', array_map( 'woocommerce_clean', $cities ) ); foreach( $cities as $city ) { if ( $city ) { $wpdb->insert( $wpdb->prefix . "woocommerce_tax_rate_locations", array( 'location_code' => $city, 'tax_rate_id' => $tax_rate_id, 'location_type' => 'city', ) ); } } } $i++; } } }