Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Countries | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| add_postcode_priority_to_country_locale | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Manipulate the WooCommerce countries settings which affect both checkout types. |
| 4 | * |
| 5 | * @package brianhenryie/bh-wc-postcode-address-autofill |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\WC_Postcode_Address_Autofill\WooCommerce; |
| 9 | |
| 10 | /** |
| 11 | * Filter the WooCommerce country locale settings. |
| 12 | * |
| 13 | * @phpstan-type FieldProperties array{priority?:int,required?:bool,hidden?:bool,label?:string,class?:array<string>} |
| 14 | */ |
| 15 | class Countries { |
| 16 | /** |
| 17 | * Ensure the postcode field's priority is higher than the city field's. |
| 18 | * |
| 19 | * Every country has different settings for ordering the checkout fields. Loop over each one and set the |
| 20 | * postcode priority. |
| 21 | * |
| 22 | * @hooked woocommerce_get_country_locale |
| 23 | * @see \WC_Countries::get_country_locale() |
| 24 | * |
| 25 | * @param array<string,array<string,FieldProperties>> $locale Array keyed by country code, containing a map of field-name:properties. |
| 26 | * |
| 27 | * @return array<string,array<string,FieldProperties>> |
| 28 | */ |
| 29 | public function add_postcode_priority_to_country_locale( array $locale ): array { |
| 30 | |
| 31 | foreach ( $locale as $key => $value ) { |
| 32 | if ( ! isset( $locale[ $key ]['postcode'] ) ) { |
| 33 | $locale[ $key ]['postcode'] = array(); |
| 34 | } |
| 35 | $locale[ $key ]['postcode']['priority'] = 65; |
| 36 | } |
| 37 | |
| 38 | return $locale; |
| 39 | } |
| 40 | } |