From d0262b5d34007e7420eae90ae3fd8e76a8131896 Mon Sep 17 00:00:00 2001 From: Jerry Smidt Date: Thu, 21 Apr 2022 15:01:21 +0200 Subject: [PATCH] Feature #55127: Improve validation/usability for autocomplete fields * Enable autoFocus option. * Hide formatted address on autocomplete-search event. * Set custom error message when address fields are not shown. * Update translation files. --- assets/js/postcode-eu-autofill.js | 5 + ...l_NL-4788a8d4bc856a79c122532ae6d25e5c.json | 28 +- .../postcodenl-address-autocomplete-nl_NL.mo | Bin 5990 -> 6660 bytes .../postcodenl-address-autocomplete-nl_NL.po | 80 ++++-- languages/postcodenl-address-autocomplete.pot | 247 +++++++++--------- postcodenl-address-autocomplete.php | 2 +- src/PostcodeNl/AddressAutocomplete/Main.php | 76 +++++- .../AddressAutocomplete/Options.php | 10 + 8 files changed, 261 insertions(+), 187 deletions(-) diff --git a/assets/js/postcode-eu-autofill.js b/assets/js/postcode-eu-autofill.js index eb6d0e7..a97d865 100644 --- a/assets/js/postcode-eu-autofill.js +++ b/assets/js/postcode-eu-autofill.js @@ -393,6 +393,7 @@ autocompleteUrl: settings.autocomplete, addressDetailsUrl: settings.getDetails, context: (countryIsoMap.get(countryToState.val()) || 'nld').toLowerCase(), + autoFocus: true, }); const getSuggestions = autocompleteInstance.getSuggestions; @@ -474,6 +475,10 @@ formRow.show(); }); + container.find('.postcode-eu-autofill-intl input').on('autocomplete-search', function () { + formRow.hide(); + }); + container.find('.postcode-eu-autofill-nl').on('address-result', function (e, result) { if (result.status !== 'valid') { diff --git a/languages/postcodenl-address-autocomplete-nl_NL-4788a8d4bc856a79c122532ae6d25e5c.json b/languages/postcodenl-address-autocomplete-nl_NL-4788a8d4bc856a79c122532ae6d25e5c.json index b82aa55..c5e07a5 100644 --- a/languages/postcodenl-address-autocomplete-nl_NL-4788a8d4bc856a79c122532ae6d25e5c.json +++ b/languages/postcodenl-address-autocomplete-nl_NL-4788a8d4bc856a79c122532ae6d25e5c.json @@ -1,27 +1 @@ -{ - "translation-revision-date": "2021-06-03 12:29+0000", - "generator": "Loco https://localise.biz/", - "source": "assets/js/postcode-eu-autofill.js", - "domain": "postcodenl-address-autocomplete", - "locale_data": { - "postcodenl-address-autocomplete": { - "": { - "domain": "postcodenl-address-autocomplete", - "lang": "nl_NL", - "plural-forms": "nplurals=2; plural=n != 1;" - }, - "Address not found.": [ - "Adres niet gevonden." - ], - "An error has occurred. Please try again later or contact us.": [ - "Er is een fout opgetreden. Probeer het later nog eens of neem contact met ons op." - ], - "Please enter a valid house number.": [ - "Vul alstublieft een geldig huisnummer in." - ], - "Please enter a valid zip/postal code.": [ - "Vul alstublieft een geldige postcode in." - ] - } - } -} \ No newline at end of file +{"translation-revision-date":"2022-04-21 12:32+0000","generator":"Loco https:\/\/localise.biz\/","source":"assets\/js\/postcode-eu-autofill.js","domain":"postcodenl-address-autocomplete","locale_data":{"postcodenl-address-autocomplete":{"":{"domain":"postcodenl-address-autocomplete","lang":"nl_NL","plural-forms":"nplurals=2; plural=n != 1;"},"Address not found.":["Adres niet gevonden."],"An error has occurred. Please try again later or contact us.":["Er is een fout opgetreden. Probeer het later nog eens of neem contact met ons op."],"Please enter a valid house number.":["Vul alstublieft een geldig huisnummer in."],"Please enter a valid zip\/postal code.":["Vul alstublieft een geldige postcode in."]}}} \ No newline at end of file diff --git a/languages/postcodenl-address-autocomplete-nl_NL.mo b/languages/postcodenl-address-autocomplete-nl_NL.mo index d227a707e8b9663f4b84152413a2bc7140a5a47b..f765cff9cb507d36ef8c85428cf07d57cb18b232 100644 GIT binary patch delta 1296 zcmb8tO-PhM9LMp0tCoh3Zq}Nn=JX<3>6)vVZ-hiBfng;`kWs5U>caBuvd`lx9oi_n zguUP<1YSa-lZU{Yo|6trM0DxU%^>O)o$EWfrG-i^yU%B4o@ZwM^LzG_f4m|2u^@9w z_?+NZ%Fo?ldLm1nHTTn8rhge%um_tmL|SnI+we7dF)LFf4-4@CR$u|Pqj|0eOYkus z7D>u1jbaAg;A#AfF+7wdl8=+fgEE5^_zEZR3z~UjJ4LE+5+C3KHsbkRBF%Ukn{Xbl z;y292?rf24_Ln{y)eLCdi<4yG6=z0&T`;(WF+wYU9|6>@7=Zl6i+r zm3(Wp&?4k30WQnTZ^t6`mpqQyiOzL9SA)^Ga)-6*4@V+ldq@RC zp}2M&e_L((aoK2I^3ObHI2?=p-$dKhaTT;f%Fz)$;Huy@HvMOA8Iw2PdG5JqF~w!Z&}6hhM4K;@{A-znj^EUFXj{vy-`XrjfvY)cN~gB1 T%V}6U*80u2UTAL7dY1DO$V3m` delta 710 zcmYMyODIH99LMoLW-u6!@ffc%DS6H{E@r$|5*sO{6jov85nE3u1<<{+U&iUVS&ON`*Y|XO~cyL(Ogr}G{pSLSYdm_ux|2k=| z&`-r}OvXdZ#S3)cBR1hD=AkD>q!8ON2mR>7MI6CXOc4o)X^DK;j71a%aT%9TCuUnk zO3=g=>_soWVm-QIMe48zdohSf_=fTLjTLB(6G=z&&sN-u3NVp|K_Sf71z2Gd8775x zET?~xAToRyMm|PJ!YYwU5jxZ*D-{eSX){ov1trwl*css z@B=lX4p!F)`%$CwBPH2Dt%vZ06P{ri{i%$|UD(AL#?P^m@izWq5+_iTdq+LU7ix0V zPOgAnq9$$_hmvk*@G3g*z-qa$*{j?huiI1YsxlkQ`rxho$6jlgjjo9icdg+w%-~aU K%fVpkrtKHRepGS* diff --git a/languages/postcodenl-address-autocomplete-nl_NL.po b/languages/postcodenl-address-autocomplete-nl_NL.po index a2dcdba..131d90d 100644 --- a/languages/postcodenl-address-autocomplete-nl_NL.po +++ b/languages/postcodenl-address-autocomplete-nl_NL.po @@ -3,7 +3,7 @@ msgstr "" "Project-Id-Version: Postcode.nl Address Autocomplete\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-05-20 13:18+0000\n" -"PO-Revision-Date: 2021-06-03 12:29+0000\n" +"PO-Revision-Date: 2022-04-21 12:32+0000\n" "Last-Translator: \n" "Language-Team: Nederlands\n" "Language: nl_NL\n" @@ -12,21 +12,47 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Loco https://localise.biz/\n" -"X-Loco-Version: 2.5.2; wp-5.7.2\n" +"X-Loco-Version: 2.6.1; wp-5.9.3\n" "X-Domain: postcodenl-address-autocomplete" -#: src/PostcodeNl/AddressAutocomplete/Main.php:126 +#: src/PostcodeNl/AddressAutocomplete/Main.php:135 msgid "- Select house number -" msgstr "- Selecteer huisnummer -" -#: src/PostcodeNl/AddressAutocomplete/Main.php:104 +#: src/PostcodeNl/AddressAutocomplete/Main.php:113 msgid "123 A" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:89 +#: src/PostcodeNl/AddressAutocomplete/Main.php:98 msgid "1234 AB" msgstr "" +#: src/PostcodeNl/AddressAutocomplete/Main.php:258 +msgid "" +"Please enter a postcode and house number for the billing address." +"" +msgstr "" +"Voer alstublieft een postcode en huisnummer in voor het factuuradres." +"" + +#: src/PostcodeNl/AddressAutocomplete/Main.php:278 +msgid "" +"Please enter a postcode and house number for the shipping address." +"" +msgstr "" +"Voer alstublieft een postcode en huisnummer in voor het verzendadres." +"" + +#: src/PostcodeNl/AddressAutocomplete/Main.php:262 +msgid "Please enter and select a billing address." +msgstr "" +"Voer alstublieft een factuuradres in en selecteer het." + +#: src/PostcodeNl/AddressAutocomplete/Main.php:282 +msgid "Please enter and select a shipping address." +msgstr "" +"Voer alstublieft een verzendadres in en selecteer het." + #: src/PostcodeNl/AddressAutocomplete/Options.php:203 msgid "active" msgstr "actief" @@ -35,17 +61,17 @@ msgstr "actief" msgid "Address field display mode" msgstr "Adres velden weergave" -#: assets/js/postcode-eu-autofill.js:244 +#: assets/js/postcode-eu-autofill.js:271 msgid "Address not found." msgstr "Adres niet gevonden." -#: assets/js/postcode-eu-autofill.js:261 +#: assets/js/postcode-eu-autofill.js:288 msgid "An error has occurred. Please try again later or contact us." msgstr "" "Er is een fout opgetreden. Probeer het later nog eens of neem contact met " "ons op." -#: src/PostcodeNl/AddressAutocomplete/Main.php:138 +#: src/PostcodeNl/AddressAutocomplete/Main.php:147 msgid "API account" msgstr "" @@ -69,11 +95,11 @@ msgstr "" msgid "Dutch address lookup method" msgstr "Zoekmethode Nederlandse adressen" -#: src/PostcodeNl/AddressAutocomplete/Main.php:205 +#: src/PostcodeNl/AddressAutocomplete/Main.php:221 msgid "Enter a postcode and house number." msgstr "Vul een postcode en huisnummer in." -#: src/PostcodeNl/AddressAutocomplete/Main.php:103 +#: src/PostcodeNl/AddressAutocomplete/Main.php:112 msgid "House number and addition" msgstr "Huisnummer en toevoeging" @@ -85,7 +111,7 @@ msgstr "Hoe de adresvelden in het checkoutformulier getoond worden." msgid "https://www.postcode.nl" msgstr "" -#. URI of the plugin +#. Plugin URI of the plugin msgid "https://www.postcode.nl/en/services/adresdata/implementatie" msgstr "https://www.postcode.nl/nl/services/adresdata/implementatie" @@ -97,7 +123,7 @@ msgstr "inactief" msgid "invalid key and/or secret" msgstr "ongeldige key en/of secret" -#. %s: options URL +#. translators: %s: options URL #: src/PostcodeNl/AddressAutocomplete/Options.php:221 #, php-format msgid "" @@ -115,16 +141,16 @@ msgstr "Niet toegankelijk." msgid "not connected" msgstr "niet verbonden" -#: assets/js/postcode-eu-autofill.js:195 +#: assets/js/postcode-eu-autofill.js:222 msgid "Please enter a valid house number." msgstr "Vul alstublieft een geldig huisnummer in." -#: assets/js/postcode-eu-autofill.js:169 +#: assets/js/postcode-eu-autofill.js:196 msgid "Please enter a valid zip/postal code." msgstr "Vul alstublieft een geldige postcode in." -#. %s: options URL -#: src/PostcodeNl/AddressAutocomplete/Main.php:267 +#. translators: %s: options URL +#: src/PostcodeNl/AddressAutocomplete/Main.php:338 #, php-format msgid "" "Please set your Postcode.eu API key and secret in the " @@ -133,11 +159,11 @@ msgstr "" "Voeg uw Postcode.nl API key en secret toe aan de opties " "om te beginnen met het gebruik van Autocomplete in uw WooCommerce checkout." -#: src/PostcodeNl/AddressAutocomplete/Main.php:88 +#: src/PostcodeNl/AddressAutocomplete/Main.php:97 msgid "Postcode" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:203 +#: src/PostcodeNl/AddressAutocomplete/Main.php:219 msgid "Postcode and house number" msgstr "Postcode en huisnummer" @@ -145,7 +171,7 @@ msgstr "Postcode en huisnummer" msgid "Postcode.eu Address Autocomplete options" msgstr "Postcode.nl Address Autocomplete opties" -#: src/PostcodeNl/AddressAutocomplete/Main.php:244 +#: src/PostcodeNl/AddressAutocomplete/Main.php:315 msgid "" "Postcode.eu Address Autocomplete requires the WooCommerce plugin to be " "activated to be able to add address autocomplete to the checkout form." @@ -154,16 +180,16 @@ msgstr "" "geactiveerd is om adres autocomplete aan het checkout formulier toe te " "kunnen voegen." -#: src/PostcodeNl/AddressAutocomplete/Main.php:264 +#: src/PostcodeNl/AddressAutocomplete/Main.php:335 msgid "Postcode.eu Address Autocomplete: Set your credentials" msgstr "Postcode.nl Address Autocomplete: inloggegevens instellen" -#: src/PostcodeNl/AddressAutocomplete/Main.php:243 +#: src/PostcodeNl/AddressAutocomplete/Main.php:314 msgid "Postcode.eu Address Autocomplete: WooCommerce is required" msgstr "Postcode.nl Address Autocomplete: WooCommerce is vereist" -#. %s: API account status. -#: src/PostcodeNl/AddressAutocomplete/Main.php:289 +#. translators: %s: API account status. +#: src/PostcodeNl/AddressAutocomplete/Main.php:360 #, php-format msgid "Postcode.eu Address Autocomplete: Your API account is %s" msgstr "Postcode.nl Address Autocomplete: Uw API account is %s" @@ -172,7 +198,7 @@ msgstr "Postcode.nl Address Autocomplete: Uw API account is %s" msgid "Postcode.nl" msgstr "" -#. Name of the plugin +#. Plugin Name of the plugin msgid "Postcode.nl Address Autocomplete" msgstr "" @@ -188,11 +214,11 @@ msgstr "" msgid "Save changes" msgstr "Wijzigingen opslaan" -#: src/PostcodeNl/AddressAutocomplete/Main.php:137 +#: src/PostcodeNl/AddressAutocomplete/Main.php:146 msgid "Settings" msgstr "Instellingen" -#: src/PostcodeNl/AddressAutocomplete/Main.php:75 +#: src/PostcodeNl/AddressAutocomplete/Main.php:84 msgid "Start typing your address or zip/postal code" msgstr "Begin met het typen van uw adres of postcode" @@ -225,7 +251,7 @@ msgstr "" msgid "The Postcode.eu API is successfully connected." msgstr "De Postcode.nl API is succesvol verbonden." -#: src/PostcodeNl/AddressAutocomplete/Main.php:118 +#: src/PostcodeNl/AddressAutocomplete/Main.php:127 msgid "Which house number do you mean?" msgstr "Welk huisnummer bedoel je?" diff --git a/languages/postcodenl-address-autocomplete.pot b/languages/postcodenl-address-autocomplete.pot index 8841871..1ffb2ab 100644 --- a/languages/postcodenl-address-autocomplete.pot +++ b/languages/postcodenl-address-autocomplete.pot @@ -1,233 +1,222 @@ -#, fuzzy +# Copyright (C) 2022 Postcode.nl +# This file is distributed under the same license as the Postcode.nl Address Autocomplete plugin. msgid "" msgstr "" -"Project-Id-Version: Postcode.nl Address Autocomplete\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-06-03 12:21+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Project-Id-Version: Postcode.nl Address Autocomplete 2.0.5\n" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/postcodenl-address-autocomplete\n" "Last-Translator: FULL NAME \n" -"Language-Team: \n" -"Language: \n" -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" +"Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Loco https://localise.biz/\n" -"X-Loco-Version: 2.5.2; wp-5.7.2\n" -"X-Domain: postcodenl-address-autocomplete" - -#: src/PostcodeNl/AddressAutocomplete/Main.php:126 -msgid "- Select house number -" -msgstr "" - -#: src/PostcodeNl/AddressAutocomplete/Main.php:104 -msgid "123 A" -msgstr "" +"POT-Creation-Date: 2022-04-21T12:41:16+00:00\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"X-Generator: WP-CLI 2.6.0\n" +"X-Domain: postcodenl-address-autocomplete\n" -#: src/PostcodeNl/AddressAutocomplete/Main.php:89 -msgid "1234 AB" +#. Plugin Name of the plugin +msgid "Postcode.nl Address Autocomplete" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:203 -msgid "active" +#. Plugin URI of the plugin +msgid "https://www.postcode.nl/en/services/adresdata/implementatie" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:120 -msgid "Address field display mode" +#. Description of the plugin +msgid "Reference implementation for Postcode.nl international address autocomplete for WooCommerce" msgstr "" -#: assets/js/postcode-eu-autofill.js:244 -msgid "Address not found." +#. Author of the plugin +msgid "Postcode.nl" msgstr "" -#: assets/js/postcode-eu-autofill.js:261 -msgid "An error has occurred. Please try again later or contact us." +#. Author URI of the plugin +msgid "https://www.postcode.nl" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:138 -msgid "API account" +#: src/PostcodeNl/AddressAutocomplete/Main.php:76 +msgid "Start typing your address or zip/postal code" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:148 -msgid "API account name" +#: src/PostcodeNl/AddressAutocomplete/Main.php:89 +msgid "Postcode" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:143 -msgid "API connection" +#: src/PostcodeNl/AddressAutocomplete/Main.php:90 +msgid "1234 AB" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:106 -msgid "API key" +#: src/PostcodeNl/AddressAutocomplete/Main.php:104 +msgid "House number and addition" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:113 -msgid "API secret" +#: src/PostcodeNl/AddressAutocomplete/Main.php:105 +msgid "123 A" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:128 -msgid "Dutch address lookup method" +#: src/PostcodeNl/AddressAutocomplete/Main.php:119 +msgid "Which house number do you mean?" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:205 -msgid "Enter a postcode and house number." +#: src/PostcodeNl/AddressAutocomplete/Main.php:127 +msgid "- Select house number -" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:103 -msgid "House number and addition" +#: src/PostcodeNl/AddressAutocomplete/Main.php:138 +msgid "Settings" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:124 -msgid "How to display the address fields in the checkout form." +#: src/PostcodeNl/AddressAutocomplete/Main.php:139 +msgid "API account" msgstr "" -#. Author URI of the plugin -msgid "https://www.postcode.nl" +#: src/PostcodeNl/AddressAutocomplete/Main.php:211 +msgid "Postcode and house number" msgstr "" -#. URI of the plugin -msgid "https://www.postcode.nl/en/services/adresdata/implementatie" +#: src/PostcodeNl/AddressAutocomplete/Main.php:213 +msgid "Enter a postcode and house number." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:207 -msgid "inactive" +#: src/PostcodeNl/AddressAutocomplete/Main.php:248 +msgid "Please enter a postcode and house number for the billing address." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:205 -msgid "invalid key and/or secret" +#: src/PostcodeNl/AddressAutocomplete/Main.php:252 +msgid "Please enter and select a billing address." msgstr "" -#. %s: options URL -#: src/PostcodeNl/AddressAutocomplete/Options.php:221 -#, php-format -msgid "" -"Make sure you used the correct Postcode.eu API subscription key and secret " -"in the options page." +#: src/PostcodeNl/AddressAutocomplete/Main.php:270 +msgid "Please enter a postcode and house number for the shipping address." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:89 -msgid "Not accessible." +#: src/PostcodeNl/AddressAutocomplete/Main.php:274 +msgid "Please enter and select a shipping address." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:201 -msgid "not connected" +#: src/PostcodeNl/AddressAutocomplete/Main.php:306 +msgid "Postcode.eu Address Autocomplete: WooCommerce is required" msgstr "" -#: assets/js/postcode-eu-autofill.js:195 -msgid "Please enter a valid house number." +#: src/PostcodeNl/AddressAutocomplete/Main.php:307 +msgid "Postcode.eu Address Autocomplete requires the WooCommerce plugin to be activated to be able to add address autocomplete to the checkout form." msgstr "" -#: assets/js/postcode-eu-autofill.js:169 -msgid "Please enter a valid zip/postal code." +#: src/PostcodeNl/AddressAutocomplete/Main.php:327 +msgid "Postcode.eu Address Autocomplete: Set your credentials" msgstr "" -#. %s: options URL -#: src/PostcodeNl/AddressAutocomplete/Main.php:267 -#, php-format -msgid "" -"Please set your Postcode.eu API key and secret in the " -"options to start using the Autocomplete in your WooCommerce checkout." +#. translators: %s: options URL +#: src/PostcodeNl/AddressAutocomplete/Main.php:330 +msgid "Please set your Postcode.eu API key and secret in the options to start using the Autocomplete in your WooCommerce checkout." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:88 -msgid "Postcode" +#. translators: %s: API account status. +#: src/PostcodeNl/AddressAutocomplete/Main.php:352 +msgid "Postcode.eu Address Autocomplete: Your API account is %s" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:203 -msgid "Postcode and house number" +#: src/PostcodeNl/AddressAutocomplete/Options.php:89 +msgid "Not accessible." msgstr "" #: src/PostcodeNl/AddressAutocomplete/Options.php:99 msgid "Postcode.eu Address Autocomplete options" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:244 -msgid "" -"Postcode.eu Address Autocomplete requires the WooCommerce plugin to be " -"activated to be able to add address autocomplete to the checkout form." +#: src/PostcodeNl/AddressAutocomplete/Options.php:106 +msgid "API key" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:264 -msgid "Postcode.eu Address Autocomplete: Set your credentials" +#: src/PostcodeNl/AddressAutocomplete/Options.php:110 +msgid "The API key is provided by Postcode.eu after completing account registration. You can also request new credentials if you lost them. Log into your Postcode.eu API account or if you do not have an account yet you can register one now." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:243 -msgid "Postcode.eu Address Autocomplete: WooCommerce is required" +#: src/PostcodeNl/AddressAutocomplete/Options.php:113 +msgid "API secret" msgstr "" -#. %s: API account status. -#: src/PostcodeNl/AddressAutocomplete/Main.php:289 -#, php-format -msgid "Postcode.eu Address Autocomplete: Your API account is %s" +#: src/PostcodeNl/AddressAutocomplete/Options.php:117 +msgid "Your API secret as provided by Postcode.eu." msgstr "" -#. Author of the plugin -msgid "Postcode.nl" +#: src/PostcodeNl/AddressAutocomplete/Options.php:120 +msgid "Address field display mode" msgstr "" -#. Name of the plugin -msgid "Postcode.nl Address Autocomplete" +#: src/PostcodeNl/AddressAutocomplete/Options.php:124 +msgid "How to display the address fields in the checkout form." msgstr "" -#. Description of the plugin -msgid "" -"Reference implementation for Postcode.nl international address autocomplete " -"for WooCommerce" +#: src/PostcodeNl/AddressAutocomplete/Options.php:128 +msgid "Dutch address lookup method" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:138 -msgid "Save changes" +#: src/PostcodeNl/AddressAutocomplete/Options.php:132 +msgid "Which method to use for Dutch address lookups. \"Full lookup\" allows searching through city and street names, the \"Postcode and house number only\" method only supports exact postcode and house number lookups but costs less per address. See product pricing." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:137 -msgid "Settings" +#: src/PostcodeNl/AddressAutocomplete/Options.php:138 +msgid "Save changes" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:75 -msgid "Start typing your address or zip/postal code" +#: src/PostcodeNl/AddressAutocomplete/Options.php:143 +msgid "API connection" msgstr "" #: src/PostcodeNl/AddressAutocomplete/Options.php:144 msgid "Subscription status" msgstr "" +#: src/PostcodeNl/AddressAutocomplete/Options.php:148 +msgid "API account name" +msgstr "" + #: src/PostcodeNl/AddressAutocomplete/Options.php:160 msgid "Supported countries" msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:110 -msgid "" -"The API key is provided by Postcode.eu after completing account registration." -" You can also request new credentials if you lost them. Log into your " -"Postcode.eu API account or if you do not have an account yet you can register one now." +#: src/PostcodeNl/AddressAutocomplete/Options.php:201 +msgid "not connected" +msgstr "" + +#: src/PostcodeNl/AddressAutocomplete/Options.php:203 +msgid "active" +msgstr "" + +#: src/PostcodeNl/AddressAutocomplete/Options.php:205 +msgid "invalid key and/or secret" +msgstr "" + +#: src/PostcodeNl/AddressAutocomplete/Options.php:207 +msgid "inactive" +msgstr "" + +#. translators: %s: options URL +#: src/PostcodeNl/AddressAutocomplete/Options.php:221 +msgid "Make sure you used the correct Postcode.eu API subscription key and secret in the options page." msgstr "" #: src/PostcodeNl/AddressAutocomplete/Options.php:225 msgid "The Postcode.eu API is successfully connected." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Main.php:118 -msgid "Which house number do you mean?" +#: src/PostcodeNl/AddressAutocomplete/Options.php:227 +msgid "Your Postcode.eu API subscription is currently inactive, please login to your account and follow the steps to activate your account." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:132 -msgid "" -"Which method to use for Dutch address lookups. \"Full lookup\" allows " -"searching through city and street names, the \"Postcode and house number " -"only\" method only supports exact postcode and house number lookups but " -"costs less per address. See product pricing." +#: assets/js/postcode-eu-autofill.js:196 +msgid "Please enter a valid zip/postal code." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:117 -msgid "Your API secret as provided by Postcode.eu." +#: assets/js/postcode-eu-autofill.js:222 +msgid "Please enter a valid house number." msgstr "" -#: src/PostcodeNl/AddressAutocomplete/Options.php:227 -msgid "" -"Your Postcode.eu API subscription is currently inactive, please login to " -"your account and follow the steps to activate your account." +#: assets/js/postcode-eu-autofill.js:271 +msgid "Address not found." +msgstr "" + +#: assets/js/postcode-eu-autofill.js:288 +msgid "An error has occurred. Please try again later or contact us." msgstr "" diff --git a/postcodenl-address-autocomplete.php b/postcodenl-address-autocomplete.php index 1a29b92..08a1aa2 100644 --- a/postcodenl-address-autocomplete.php +++ b/postcodenl-address-autocomplete.php @@ -3,7 +3,7 @@ * Plugin Name: Postcode.nl Address Autocomplete * Plugin URI: https://www.postcode.nl/en/services/adresdata/implementatie * Description: Reference implementation for Postcode.nl international address autocomplete for WooCommerce - * Version: 2.0.4 + * Version: 2.0.5 * Author: Postcode.nl * Author URI: https://www.postcode.nl * Text Domain: postcodenl-address-autocomplete diff --git a/src/PostcodeNl/AddressAutocomplete/Main.php b/src/PostcodeNl/AddressAutocomplete/Main.php index e99a2de..dbb4e6d 100644 --- a/src/PostcodeNl/AddressAutocomplete/Main.php +++ b/src/PostcodeNl/AddressAutocomplete/Main.php @@ -10,7 +10,7 @@ class Main { /** @var string The version number of the plugin should be equal to the commented version number in ../../../postcodenl-address-autocomplete.php */ - public const VERSION = '2.0.4'; + public const VERSION = '2.0.5'; /** @var self Reference to own */ protected static $_instance; @@ -37,7 +37,7 @@ public function __construct() public function wordPressInit(): void { add_filter('woocommerce_default_address_fields', [$this, 'addressFields']); - add_filter('plugin_action_links_' . $this->getPluginFileAndPath(), [$this, 'pluginActionLinks']); + add_filter('plugin_action_links_' . $this->_getPluginFileAndPath(), [$this, 'pluginActionLinks']); add_action('admin_enqueue_scripts', [$this, 'enqueueAdminScripts']); @@ -54,6 +54,7 @@ public function wordPressInit(): void add_action('woocommerce_after_checkout_form', [$this, 'afterCheckoutForm']); add_action('woocommerce_after_edit_account_address_form', [$this, 'afterCheckoutForm']); + add_action('woocommerce_after_checkout_validation', [$this, 'afterCheckoutValidation'], 10, 2); add_action('admin_menu', [$this->_options, 'addPluginPage']); @@ -221,6 +222,61 @@ public function afterCheckoutForm(): void ); } + public function afterCheckoutValidation($fields, $errors) + { + if (!$this->_options->hasKeyAndSecret() || $this->_options->hasEditableAddressFields()) + { + return $fields; + } + + $fieldNames = ['address_1', 'postcode', 'city']; + $errorCodes = $errors->get_error_codes(); + + if ($this->_isSupportedCountryIso2($fields['billing_country'])) + { + $billingRequiredCodes = array_map(fn($name) => 'billing_' . $name . '_required', $fieldNames); + + if (count(array_intersect($errorCodes, $billingRequiredCodes)) > 0) + { + foreach ($billingRequiredCodes as $code) + { + $errors->remove($code); + } + + if ($this->_options->isNlModePostcodeOnly() && $fields['billing_country'] === 'NL') + { + $errors->add('validation', __('Please enter a postcode and house number for the billing address.', 'postcodenl-address-autocomplete')); + } + else + { + $errors->add('validation', __('Please enter and select a billing address.', 'postcodenl-address-autocomplete')); + } + } + } + + if ($this->_isSupportedCountryIso2($fields['shipping_country'])) + { + $shippingRequiredCodes = array_map(fn($name) => 'shipping_' . $name . '_required', $fieldNames); + + if (count(array_intersect($errorCodes, $shippingRequiredCodes)) > 0) + { + foreach ($shippingRequiredCodes as $code) + { + $errors->remove($code); + } + + if ($this->_options->isNlModePostcodeOnly() && $fields['shipping_country'] === 'NL') + { + $errors->add('validation', __('Please enter a postcode and house number for the shipping address.', 'postcodenl-address-autocomplete')); + } + else + { + $errors->add('validation', __('Please enter and select a shipping address.', 'postcodenl-address-autocomplete')); + } + } + } + } + public function getOptions(): Options { return $this->_options; @@ -306,8 +362,22 @@ public static function getInstance(): self return static::$_instance; } - protected function getPluginFileAndPath(): string + protected function _getPluginFileAndPath(): string { return plugin_basename(dirname(__FILE__, 4) . '/postcodenl-address-autocomplete.php'); } + + protected function _isSupportedCountryIso2($countryCode): bool + { + foreach ($this->_options->getSupportedCountries() as $country) + { + if ($countryCode === $country['iso2']) + { + return true; + } + } + + return false; + } + } diff --git a/src/PostcodeNl/AddressAutocomplete/Options.php b/src/PostcodeNl/AddressAutocomplete/Options.php index 7d85a56..8aeb34f 100644 --- a/src/PostcodeNl/AddressAutocomplete/Options.php +++ b/src/PostcodeNl/AddressAutocomplete/Options.php @@ -393,4 +393,14 @@ protected function _getData(): array 'apiAccountName' => $this->_apiAccountName, ]; } + + public function hasEditableAddressFields(): bool + { + return $this->displayMode === static::DISPLAY_MODE_SHOW_ALL; + } + + public function isNlModePostcodeOnly(): bool + { + return $this->netherlandsMode === static::NETHERLANDS_MODE_POSTCODE_ONLY; + } }