Skip to content

Commit

Permalink
Bug #57928: Signal compatibility with HPOS for WooCommerce 8.2.0
Browse files Browse the repository at this point in the history
- Update WooCommerce compatibility versionto 8.2.0
- Updated version number
  • Loading branch information
BastiaanGrutters committed Oct 16, 2023
1 parent 36eab10 commit 1838ed8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
38 changes: 32 additions & 6 deletions assets/js/postcode-eu-autofill.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

// Wrap in timeout to execute after Woocommerce field logic:
window.setTimeout(function () {
toggleAddressFields(getAddressFields(container), !isSupportedCountry(selectedCountry), true);
toggleAddressFields(getAddressFields(container), !isSupportedCountry(selectedCountry), true, isSupportedCountry(selectedCountry));
});
}).trigger('change.postcode-eu.address-fields');
})
Expand Down Expand Up @@ -96,7 +96,7 @@
}
}

const toggleAddressFields = function (addressFields, state, force)
const toggleAddressFields = function (addressFields, state, force, isSupportedCountry)
{
if (!force)
{
Expand All @@ -120,7 +120,33 @@

if (field.length > 0 && field.prop('type') !== 'hidden')
{
field.closest('.form-row').toggle(state);
let formRow = field.closest('.form-row');
formRow.toggle(state);
let input = formRow.find('input[type="text"]');
if (input.length === 0)
{
continue;
}
if (state && !isSupportedCountry)
{
let previousValue = input.attr('previous-autocomplete');
if (previousValue)
{
input.attr('autocomplete', previousValue);
}
else
{
input.attr('autocomplete', null);
}
}
else
{
if (!input.attr('previous-autocomplete'))
{
input.attr('previous-autocomplete', input.attr('autocomplete'));
}
input.attr('autocomplete', 'off');
}
}
}
}
Expand Down Expand Up @@ -547,7 +573,7 @@

const callback = (result) => {
fillAddressFieldsIntl(result);
toggleAddressFields(addressFields, true);
toggleAddressFields(addressFields, true, false, true);
intlField
.removeClass('postcodenl-address-autocomplete-loading')
.trigger('address-result', result);
Expand Down Expand Up @@ -607,7 +633,7 @@

document.addEventListener('autocomplete-xhrerror', function (e) {
console.error('Autocomplete XHR error', e);
toggleAddressFields(addressFields, true);
toggleAddressFields(addressFields, true, false, true);
intlField.removeClass('postcodenl-address-autocomplete-loading')
setFieldValidity(
intlField,
Expand Down Expand Up @@ -728,7 +754,7 @@
link = $('<a>', {'class': 'postcode-eu-autofill-intl-bypass-link', text: settings.autofillIntlBypassLinkText});

link.on('click', function () {
toggleAddressFields(getAddressFields(container), true, true);
toggleAddressFields(getAddressFields(container), true, true, true);
formRow.hide();
return false;
});
Expand Down
16 changes: 14 additions & 2 deletions postcodenl-address-autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
* 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.1.1
* Version: 2.1.2
* Author: Postcode.nl
* Author URI: https://www.postcode.nl
* Text Domain: postcodenl-address-autocomplete
* Requires at least: 5.2.0
* Requires PHP: 7.3.0
*
* WC requires at least: 3.7.0
* WC tested up to: 7.5.0
* WC tested up to: 8.2.0
*/

use Automattic\WooCommerce\Utilities\FeaturesUtil;
use PostcodeNl\AddressAutocomplete\Main;

defined('ABSPATH') || exit;
Expand All @@ -39,3 +40,14 @@
});

new Main();

/**
* @see https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book#declaring-extension-incompatibility
*/
add_action('before_woocommerce_init', function() {
if (!class_exists('Automattic\\WooCommerce\\Utilities\\FeaturesUtil'))
{
return;
}
FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
});
3 changes: 1 addition & 2 deletions src/PostcodeNl/AddressAutocomplete/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.1.1';
public const VERSION = '2.1.2';

/** @var self Reference to own */
protected static $_instance;
Expand All @@ -30,7 +30,6 @@ public function __construct()
$this->loadOptions();

add_action('init', [$this, 'wordPressInit']);

static::$_instance = $this;
}

Expand Down

0 comments on commit 1838ed8

Please sign in to comment.