Changeset 2878134
- Timestamp:
- 03/10/2023 08:50:25 PM (3 years ago)
- Location:
- address-autocomplete-google-places
- Files:
-
- 8 edited
- 1 copied
-
tags/1.1.0 (copied) (copied from address-autocomplete-google-places/trunk)
-
tags/1.1.0/address-autocomplete.php (modified) (4 diffs)
-
tags/1.1.0/assets/address-autocomplete.js (modified) (2 diffs)
-
tags/1.1.0/languages/address-autocomplete.pot (modified) (3 diffs)
-
tags/1.1.0/readme.txt (modified) (2 diffs)
-
trunk/address-autocomplete.php (modified) (4 diffs)
-
trunk/assets/address-autocomplete.js (modified) (2 diffs)
-
trunk/languages/address-autocomplete.pot (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
address-autocomplete-google-places/tags/1.1.0/address-autocomplete.php
r2860332 r2878134 4 4 * Plugin URI: https://github.com/devpress/address-autocomplete-google-places 5 5 * Description: Enables address autocomplete with Google Places API for WooCommerce. 6 * Version: 1. 0.16 * Version: 1.1.0 7 7 * Author: DevPress 8 8 * Author URI: https://devpress.com 9 9 * Text Domain: address-autocomplete-google-places 10 * Requires at least: 5.910 * Requires at least: 6.0 11 11 * Requires PHP: 7.2 12 12 * Tested up to: 6.1.1 … … 29 29 30 30 /** @var string */ 31 public static $version = '1. 0.1';31 public static $version = '1.1.0'; 32 32 33 33 /** @var string */ … … 60 60 self::$dir = plugin_dir_path( __FILE__ ); 61 61 62 // On plugins page adds link to the settings. 62 // Declares compatibility with High Performance Order Storage. 63 add_action( 'before_woocommerce_init', array( $this, 'declare_custom_order_table_compatibility' ) ); 64 65 // Adds link to settings from plugins page. 63 66 $base_name = plugin_basename( __FILE__ ); 64 67 add_filter( 'plugin_action_links_' . $base_name, array( $this, 'plugin_action_links' ) ); … … 67 70 add_action( 'plugins_loaded', array( $this, 'init' ) ); 68 71 } 72 73 /** 74 * Declares compatibility with High Performance Order Storage. 75 * https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book 76 */ 77 public function declare_custom_order_table_compatibility() { 78 if ( ! class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { 79 return; 80 } 81 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); 82 } 83 69 84 70 85 /** -
address-autocomplete-google-places/tags/1.1.0/assets/address-autocomplete.js
r2860332 r2878134 93 93 countryAllowList = [country]; 94 94 } 95 96 95 address.setComponentRestrictions({ 97 96 country: countryAllowList, … … 103 102 */ 104 103 parsePlace = (address, fieldInputs) => { 105 let place = address.getPlace(); 106 let streetNumber = ""; 107 let route = ""; 108 109 for (let i = 0; i < place.address_components.length; i++) { 110 const type = place.address_components[i].types[0]; 111 const shortName = place.address_components[i].short_name; 112 const longName = place.address_components[i].long_name; 113 114 // Street number. 115 if (type === "street_number") { 116 streetNumber = longName; 117 continue; 104 const place = address.getPlace(); 105 const addressComponents = place.address_components; 106 107 // Get country first since address components vary by country. 108 const country = this.getAddressComponentShortName( 109 addressComponents, 110 "country" 111 ); 112 113 // Set the country field. 114 const countryField = fieldInputs.country; 115 countryField.value = country; 116 countryField.dispatchEvent(new Event("change")); 117 118 // Set the address1 field. 119 fieldInputs.address1.value = this.parseStreetAddress(addressComponents); 120 121 // Set the city field. 122 // Requires the country to properly parse. 123 fieldInputs.city.value = this.parseCity(addressComponents, country); 124 125 // Set the state field. 126 const stateField = fieldInputs.state; 127 const stateComponent = this.getAddressComponent( 128 addressComponents, 129 "administrative_area_level_1" 130 ); 131 if (stateField.tagName == "SELECT") { 132 stateField.value = stateComponent.short_name; 133 Array.prototype.forEach.call(stateField.options, function (option) { 134 if (stateComponent.short_name == option.value) { 135 option.selected = true; 136 return true; 137 } 138 }); 139 } else { 140 stateField.value = stateComponent.long_name; 141 } 142 stateField.dispatchEvent(new Event("change")); 143 144 // Set the postal code field. 145 fieldInputs.postcode.value = this.getAddressComponentLongName( 146 addressComponents, 147 "postal_code" 148 ); 149 }; 150 151 /** 152 * Parse address1 from address components. 153 * 154 * @return {string} The street address. 155 */ 156 parseStreetAddress = (addressComponents) => { 157 const streetNumber = this.getAddressComponentLongName( 158 addressComponents, 159 "street_number" 160 ); 161 const route = this.getAddressComponentLongName( 162 addressComponents, 163 "route" 164 ); 165 return `${streetNumber} ${route}`.trim(); 166 }; 167 168 /** 169 * Parse city from address components. 170 * 171 * @return {string} The city. 172 */ 173 parseCity = (addressComponents, country) => { 174 // Different countries use different address components for city. 175 let city = ""; 176 177 // GB has some oddities with city names. 178 if ("GB" === country) { 179 city = this.getAddressComponentLongName( 180 addressComponents, 181 "postal_town" 182 ); 183 if (city === "") { 184 city = this.getAddressComponentLongName( 185 addressComponents, 186 "administrative_area_level_2" 187 ); 118 188 } 119 120 // Street name. 121 if (type === "route") { 122 route = longName; 123 continue; 124 } 125 126 // City. 127 if (type === "sublocality_level_1" || type === "locality") { 128 fieldInputs.city.value = longName; 129 continue; 130 } 131 132 // State. 133 if (type === "administrative_area_level_1") { 134 const stateField = fieldInputs.state; 135 if (stateField.tagName == "SELECT") { 136 stateField.value = shortName; 137 Array.prototype.forEach.call( 138 stateField.options, 139 function (option) { 140 if (shortName == option.value) { 141 option.selected = true; 142 return true; 143 } 144 } 145 ); 146 } else { 147 stateField.value = longName; 148 } 149 stateField.dispatchEvent(new Event("change")); 150 continue; 151 } 152 153 // Country. 154 if (type === "country") { 155 const countryField = fieldInputs.country; 156 countryField.value = shortName; 157 countryField.dispatchEvent(new Event("change")); 158 continue; 159 } 160 161 // Postal code. 162 if (type === "postal_code") { 163 fieldInputs.postcode.value = longName; 164 continue; 165 } 166 } 167 168 // Populate address1 field. 169 fieldInputs.address1.value = streetNumber + " " + route; 189 return city; 190 } 191 192 const locality = this.getAddressComponentLongName( 193 addressComponents, 194 "locality" 195 ); 196 197 if (locality !== "") { 198 return locality; 199 } 200 201 const sublocality = this.getAddressComponentLongName( 202 addressComponents, 203 "sublocality_level_1" 204 ); 205 206 if (sublocality !== "") { 207 return sublocality; 208 } 209 210 return ""; 211 }; 212 213 /** 214 * Gets the shortname for the address component. 215 * 216 * @return {string} The shortname. 217 */ 218 getAddressComponentShortName = (addressComponents, key) => { 219 const component = this.getAddressComponent(addressComponents, key); 220 return component.short_name ?? ""; 221 }; 222 223 /** 224 * Gets the longname for the address component. 225 * 226 * @return {string} The shortname. 227 */ 228 getAddressComponentLongName = (addressComponents, key) => { 229 const component = this.getAddressComponent(addressComponents, key); 230 return component.long_name ?? ""; 231 }; 232 233 /** 234 * Filters the address components by type key. 235 * 236 * @return {object} The address component. 237 */ 238 getAddressComponent = (addressComponents, key) => { 239 const component = addressComponents.filter((address) => 240 address.types.includes(key) 241 ); 242 return component[0] ?? []; 170 243 }; 171 244 -
address-autocomplete-google-places/tags/1.1.0/languages/address-autocomplete.pot
r2860332 r2878134 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Address Autocomplete Google Places 1. 0.0\n"5 "Project-Id-Version: Address Autocomplete Google Places 1.1.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/address-autocomplete-google-places\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2023-0 1-29T23:23:29+00:00\n"12 "POT-Creation-Date: 2023-03-10T20:47:35+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.6.0\n" … … 35 35 msgstr "" 36 36 37 #: address-autocomplete.php:1 0137 #: address-autocomplete.php:119 38 38 msgid "Address Autocomplete requires at least WooCommerce v%1$s in order to function." 39 39 msgstr "" 40 40 41 #: address-autocomplete.php:1 1541 #: address-autocomplete.php:133 42 42 msgid "Settings" 43 43 msgstr "" -
address-autocomplete-google-places/tags/1.1.0/readme.txt
r2860332 r2878134 4 4 Tags: woocommerce 5 5 Requires at least: 6.0 6 Tested up to: 6. 07 Stable tag: 1. 0.16 Tested up to: 6.1.1 7 Stable tag: 1.1.0 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 49 49 == Changelog == 50 50 51 = 1.1.0 = 52 53 * Update: Declare compatibility for High Performance Order Storage. 54 * Update: Improves methods for parsing address components. 55 51 56 = 1.0.1 = 52 57 -
address-autocomplete-google-places/trunk/address-autocomplete.php
r2860332 r2878134 4 4 * Plugin URI: https://github.com/devpress/address-autocomplete-google-places 5 5 * Description: Enables address autocomplete with Google Places API for WooCommerce. 6 * Version: 1. 0.16 * Version: 1.1.0 7 7 * Author: DevPress 8 8 * Author URI: https://devpress.com 9 9 * Text Domain: address-autocomplete-google-places 10 * Requires at least: 5.910 * Requires at least: 6.0 11 11 * Requires PHP: 7.2 12 12 * Tested up to: 6.1.1 … … 29 29 30 30 /** @var string */ 31 public static $version = '1. 0.1';31 public static $version = '1.1.0'; 32 32 33 33 /** @var string */ … … 60 60 self::$dir = plugin_dir_path( __FILE__ ); 61 61 62 // On plugins page adds link to the settings. 62 // Declares compatibility with High Performance Order Storage. 63 add_action( 'before_woocommerce_init', array( $this, 'declare_custom_order_table_compatibility' ) ); 64 65 // Adds link to settings from plugins page. 63 66 $base_name = plugin_basename( __FILE__ ); 64 67 add_filter( 'plugin_action_links_' . $base_name, array( $this, 'plugin_action_links' ) ); … … 67 70 add_action( 'plugins_loaded', array( $this, 'init' ) ); 68 71 } 72 73 /** 74 * Declares compatibility with High Performance Order Storage. 75 * https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book 76 */ 77 public function declare_custom_order_table_compatibility() { 78 if ( ! class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { 79 return; 80 } 81 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); 82 } 83 69 84 70 85 /** -
address-autocomplete-google-places/trunk/assets/address-autocomplete.js
r2860332 r2878134 93 93 countryAllowList = [country]; 94 94 } 95 96 95 address.setComponentRestrictions({ 97 96 country: countryAllowList, … … 103 102 */ 104 103 parsePlace = (address, fieldInputs) => { 105 let place = address.getPlace(); 106 let streetNumber = ""; 107 let route = ""; 108 109 for (let i = 0; i < place.address_components.length; i++) { 110 const type = place.address_components[i].types[0]; 111 const shortName = place.address_components[i].short_name; 112 const longName = place.address_components[i].long_name; 113 114 // Street number. 115 if (type === "street_number") { 116 streetNumber = longName; 117 continue; 104 const place = address.getPlace(); 105 const addressComponents = place.address_components; 106 107 // Get country first since address components vary by country. 108 const country = this.getAddressComponentShortName( 109 addressComponents, 110 "country" 111 ); 112 113 // Set the country field. 114 const countryField = fieldInputs.country; 115 countryField.value = country; 116 countryField.dispatchEvent(new Event("change")); 117 118 // Set the address1 field. 119 fieldInputs.address1.value = this.parseStreetAddress(addressComponents); 120 121 // Set the city field. 122 // Requires the country to properly parse. 123 fieldInputs.city.value = this.parseCity(addressComponents, country); 124 125 // Set the state field. 126 const stateField = fieldInputs.state; 127 const stateComponent = this.getAddressComponent( 128 addressComponents, 129 "administrative_area_level_1" 130 ); 131 if (stateField.tagName == "SELECT") { 132 stateField.value = stateComponent.short_name; 133 Array.prototype.forEach.call(stateField.options, function (option) { 134 if (stateComponent.short_name == option.value) { 135 option.selected = true; 136 return true; 137 } 138 }); 139 } else { 140 stateField.value = stateComponent.long_name; 141 } 142 stateField.dispatchEvent(new Event("change")); 143 144 // Set the postal code field. 145 fieldInputs.postcode.value = this.getAddressComponentLongName( 146 addressComponents, 147 "postal_code" 148 ); 149 }; 150 151 /** 152 * Parse address1 from address components. 153 * 154 * @return {string} The street address. 155 */ 156 parseStreetAddress = (addressComponents) => { 157 const streetNumber = this.getAddressComponentLongName( 158 addressComponents, 159 "street_number" 160 ); 161 const route = this.getAddressComponentLongName( 162 addressComponents, 163 "route" 164 ); 165 return `${streetNumber} ${route}`.trim(); 166 }; 167 168 /** 169 * Parse city from address components. 170 * 171 * @return {string} The city. 172 */ 173 parseCity = (addressComponents, country) => { 174 // Different countries use different address components for city. 175 let city = ""; 176 177 // GB has some oddities with city names. 178 if ("GB" === country) { 179 city = this.getAddressComponentLongName( 180 addressComponents, 181 "postal_town" 182 ); 183 if (city === "") { 184 city = this.getAddressComponentLongName( 185 addressComponents, 186 "administrative_area_level_2" 187 ); 118 188 } 119 120 // Street name. 121 if (type === "route") { 122 route = longName; 123 continue; 124 } 125 126 // City. 127 if (type === "sublocality_level_1" || type === "locality") { 128 fieldInputs.city.value = longName; 129 continue; 130 } 131 132 // State. 133 if (type === "administrative_area_level_1") { 134 const stateField = fieldInputs.state; 135 if (stateField.tagName == "SELECT") { 136 stateField.value = shortName; 137 Array.prototype.forEach.call( 138 stateField.options, 139 function (option) { 140 if (shortName == option.value) { 141 option.selected = true; 142 return true; 143 } 144 } 145 ); 146 } else { 147 stateField.value = longName; 148 } 149 stateField.dispatchEvent(new Event("change")); 150 continue; 151 } 152 153 // Country. 154 if (type === "country") { 155 const countryField = fieldInputs.country; 156 countryField.value = shortName; 157 countryField.dispatchEvent(new Event("change")); 158 continue; 159 } 160 161 // Postal code. 162 if (type === "postal_code") { 163 fieldInputs.postcode.value = longName; 164 continue; 165 } 166 } 167 168 // Populate address1 field. 169 fieldInputs.address1.value = streetNumber + " " + route; 189 return city; 190 } 191 192 const locality = this.getAddressComponentLongName( 193 addressComponents, 194 "locality" 195 ); 196 197 if (locality !== "") { 198 return locality; 199 } 200 201 const sublocality = this.getAddressComponentLongName( 202 addressComponents, 203 "sublocality_level_1" 204 ); 205 206 if (sublocality !== "") { 207 return sublocality; 208 } 209 210 return ""; 211 }; 212 213 /** 214 * Gets the shortname for the address component. 215 * 216 * @return {string} The shortname. 217 */ 218 getAddressComponentShortName = (addressComponents, key) => { 219 const component = this.getAddressComponent(addressComponents, key); 220 return component.short_name ?? ""; 221 }; 222 223 /** 224 * Gets the longname for the address component. 225 * 226 * @return {string} The shortname. 227 */ 228 getAddressComponentLongName = (addressComponents, key) => { 229 const component = this.getAddressComponent(addressComponents, key); 230 return component.long_name ?? ""; 231 }; 232 233 /** 234 * Filters the address components by type key. 235 * 236 * @return {object} The address component. 237 */ 238 getAddressComponent = (addressComponents, key) => { 239 const component = addressComponents.filter((address) => 240 address.types.includes(key) 241 ); 242 return component[0] ?? []; 170 243 }; 171 244 -
address-autocomplete-google-places/trunk/languages/address-autocomplete.pot
r2860332 r2878134 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Address Autocomplete Google Places 1. 0.0\n"5 "Project-Id-Version: Address Autocomplete Google Places 1.1.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/address-autocomplete-google-places\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2023-0 1-29T23:23:29+00:00\n"12 "POT-Creation-Date: 2023-03-10T20:47:35+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.6.0\n" … … 35 35 msgstr "" 36 36 37 #: address-autocomplete.php:1 0137 #: address-autocomplete.php:119 38 38 msgid "Address Autocomplete requires at least WooCommerce v%1$s in order to function." 39 39 msgstr "" 40 40 41 #: address-autocomplete.php:1 1541 #: address-autocomplete.php:133 42 42 msgid "Settings" 43 43 msgstr "" -
address-autocomplete-google-places/trunk/readme.txt
r2860332 r2878134 4 4 Tags: woocommerce 5 5 Requires at least: 6.0 6 Tested up to: 6. 07 Stable tag: 1. 0.16 Tested up to: 6.1.1 7 Stable tag: 1.1.0 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 49 49 == Changelog == 50 50 51 = 1.1.0 = 52 53 * Update: Declare compatibility for High Performance Order Storage. 54 * Update: Improves methods for parsing address components. 55 51 56 = 1.0.1 = 52 57
Note: See TracChangeset
for help on using the changeset viewer.