Automattic\WooCommerce\Database\Migrations
MigrationHelper::migrate_country_states_for_store_location
Migrate the state code for the store location.
Method of the class: MigrationHelper{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = MigrationHelper::migrate_country_states_for_store_location( $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_store_location() MigrationHelper::migrate country states for store location code WC 10.5.0
private static function migrate_country_states_for_store_location( string $country_code, array $old_to_new_states_mapping ): void {
$store_location = get_option( 'woocommerce_default_country', '' );
if ( StringUtil::starts_with( $store_location, "{$country_code}:" ) ) {
$old_location_code = substr( $store_location, 3 );
if ( array_key_exists( $old_location_code, $old_to_new_states_mapping ) ) {
$new_location_code = "{$country_code}:{$old_to_new_states_mapping[$old_location_code]}";
update_option( 'woocommerce_default_country', $new_location_code );
}
}
}