Automattic\WooCommerce\Database\Migrations

MigrationHelper::migrate_country_states_for_tax_rates()private staticWC 1.0

Migrate state codes in the tax rates table.

Method of the class: MigrationHelper{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = MigrationHelper::migrate_country_states_for_tax_rates( $country_code, $old_to_new_states_mapping ): void;
$country_code(string) (required)
The country that has the states for which the migration is needed.
$old_to_new_states_mapping(array) (required)
An associative array where keys are the old state codes and values are the new state codes.

MigrationHelper::migrate_country_states_for_tax_rates() code WC 8.6.1

private static function migrate_country_states_for_tax_rates( string $country_code, array $old_to_new_states_mapping ): void {
	global $wpdb;

	foreach ( $old_to_new_states_mapping as $old_state_code => $new_state_code ) {
		$wpdb->query(
			$wpdb->prepare(
				"UPDATE {$wpdb->prefix}woocommerce_tax_rates SET tax_rate_state=%s WHERE tax_rate_country=%s AND tax_rate_state=%s",
				$new_state_code,
				$country_code,
				$old_state_code
			)
		);
	}
}