Refactor Country Specs to use in operator (#51162)

* Refactor Country Specs to use in operator

* Add changelog

* Refactor shipping specs
This commit is contained in:
Chi-Hsuan Huang 2024-09-06 15:45:49 +08:00 committed by GitHub
parent b4f1062783
commit 19661e3317
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 106 additions and 468 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: performance
Refactor Country Specs to use 'in' operator

View File

@ -316,19 +316,10 @@ class DefaultShippingPartners {
* @return object Rules to match. * @return object Rules to match.
*/ */
public static function get_rules_for_countries( $countries ) { public static function get_rules_for_countries( $countries ) {
$rules = array();
foreach ( $countries as $country ) {
$rules[] = (object) array(
'type' => 'base_location_country',
'value' => $country,
'operation' => '=',
);
}
return (object) array( return (object) array(
'type' => 'or', 'type' => 'base_location_country',
'operands' => $rules, 'operation' => 'in',
'value' => $countries,
); );
} }
} }

View File

@ -184,205 +184,50 @@ class DefaultFreeExtensions {
'</a>' '</a>'
), ),
'is_visible' => array( 'is_visible' => array(
array(
'type' => 'or',
'operands' => array(
array( array(
'type' => 'base_location_country', 'type' => 'base_location_country',
'value' => 'US', 'value' => array(
'operation' => '=', 'US',
), 'PR',
array( 'AU',
'type' => 'base_location_country', 'CA',
'value' => 'PR', 'DE',
'operation' => '=', 'ES',
), 'FR',
array( 'GB',
'type' => 'base_location_country', 'IE',
'value' => 'AU', 'IT',
'operation' => '=', 'NZ',
), 'AT',
array( 'BE',
'type' => 'base_location_country', 'NL',
'value' => 'CA', 'PL',
'operation' => '=', 'PT',
), 'CH',
array( 'HK',
'type' => 'base_location_country', 'SG',
'value' => 'DE', 'CY',
'operation' => '=', 'DK',
), 'EE',
array( 'FI',
'type' => 'base_location_country', 'GR',
'value' => 'ES', 'LU',
'operation' => '=', 'LT',
), 'LV',
array( 'NO',
'type' => 'base_location_country', 'MT',
'value' => 'FR', 'SI',
'operation' => '=', 'SK',
), 'BG',
array( 'CZ',
'type' => 'base_location_country', 'HR',
'value' => 'GB', 'HU',
'operation' => '=', 'RO',
), 'SE',
array( 'JP',
'type' => 'base_location_country', 'AE',
'value' => 'IE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'IT',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'NZ',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'AT',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'BE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'NL',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'PL',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'PT',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'CH',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'HK',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'SG',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'CY',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'DK',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'EE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'FI',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'GR',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'LU',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'LT',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'LV',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'NO',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'MT',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'SI',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'SK',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'BG',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'CZ',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'HR',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'HU',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'RO',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'SE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'JP',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'AE',
'operation' => '=',
),
), ),
'operation' => 'in',
), ),
DefaultPaymentGateways::get_rules_for_cbd( false ), DefaultPaymentGateways::get_rules_for_cbd( false ),
), ),
@ -577,210 +422,51 @@ class DefaultFreeExtensions {
__( 'Grow your online sales by promoting your products on TikTok to over one billion monthly active users around the world.', 'woocommerce' ), __( 'Grow your online sales by promoting your products on TikTok to over one billion monthly active users around the world.', 'woocommerce' ),
'manage_url' => 'admin.php?page=tiktok', 'manage_url' => 'admin.php?page=tiktok',
'is_visible' => array( 'is_visible' => array(
array(
'type' => 'or',
'operands' => array(
array( array(
'type' => 'base_location_country', 'type' => 'base_location_country',
'value' => 'US', 'value' => array(
'operation' => '=', 'US',
), 'CA',
array( 'MX',
'type' => 'base_location_country', 'AT',
'value' => 'CA', 'BE',
'operation' => '=', 'CZ',
), 'DK',
array( 'FI',
'type' => 'base_location_country', 'FR',
'value' => 'MX', 'DE',
'operation' => '=', 'GR',
), 'HU',
array( 'IE',
'type' => 'base_location_country', 'IT',
'value' => 'AT', 'NL',
'operation' => '=', 'PL',
), 'PT',
array( 'RO',
'type' => 'base_location_country', 'ES',
'value' => 'BE', 'SE',
'operation' => '=', 'GB',
), 'CH',
array( 'NO',
'type' => 'base_location_country', 'AU',
'value' => 'CZ', 'NZ',
'operation' => '=', 'SG',
), 'MY',
array( 'PH',
'type' => 'base_location_country', 'ID',
'value' => 'DK', 'VN',
'operation' => '=', 'TH',
), 'KR',
array( 'IL',
'type' => 'base_location_country', 'AE',
'value' => 'FI', 'RU',
'operation' => '=', 'UA',
), 'TR',
array( 'SA',
'type' => 'base_location_country', 'BR',
'value' => 'FR', 'JP',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'DE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'GR',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'HU',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'IE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'IT',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'NL',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'PL',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'PT',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'RO',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'ES',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'SE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'GB',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'CH',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'NO',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'AU',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'NZ',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'SG',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'MY',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'PH',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'ID',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'VN',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'TH',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'KR',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'IL',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'AE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'RU',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'UA',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'TR',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'SA',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'BR',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'JP',
'operation' => '=',
),
), ),
'operation' => 'in',
), ),
), ),
'is_built_by_wc' => false, 'is_built_by_wc' => false,
@ -997,63 +683,20 @@ class DefaultFreeExtensions {
*/ */
private static function get_rules_for_wcservices_tax_countries() { private static function get_rules_for_wcservices_tax_countries() {
return array( return array(
'type' => 'or',
'operands' => array(
array(
'type' => 'base_location_country', 'type' => 'base_location_country',
'value' => 'US', 'operation' => 'in',
'operation' => '=', 'value' => array(
), 'US',
array( 'FR',
'type' => 'base_location_country', 'GB',
'value' => 'FR', 'DE',
'operation' => '=', 'CA',
), 'AU',
array( 'GR',
'type' => 'base_location_country', 'BE',
'value' => 'GB', 'PT',
'operation' => '=', 'DK',
), 'SE',
array(
'type' => 'base_location_country',
'value' => 'DE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'CA',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'AU',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'GR',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'BE',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'PT',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'DK',
'operation' => '=',
),
array(
'type' => 'base_location_country',
'value' => 'SE',
'operation' => '=',
),
), ),
); );
} }