Created
July 6, 2023 15:45
-
-
Save webdados/67b40cd6fb8396d58c13f7da77949d83 to your computer and use it in GitHub Desktop.
Postcode before other address fields for "Portuguese Postcodes for WooCommerce" full address autocomplete mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* You should adapt the priorities to your scenario */ | |
add_filter( 'woocommerce_get_country_locale', function( $countries ) { | |
if ( is_checkout() ) { | |
if ( function_exists( '\Webdados\PortuguesePostcodesWooCommerce\PortuguesePostcodesWooCommerce' ) ) { | |
if ( get_option( 'portuguese_postcodes_woo_mode' ) == '' && get_option( 'portuguese_postcodes_woo_autocomplete_mode' ) == 'full_address' ) { | |
$countries['PT']['postcode']['priority'] = 45; | |
$countries['PT']['city']['priority'] = 46; | |
if ( ! ( function_exists( 'woocommerce_portugal_states' ) || class_exists( 'WC_Webdados_Distritos' ) ) ) { | |
// Without the Distritos plugin active | |
$countries['PT']['postcode_before_city'] = true; | |
// Optionally side by side | |
$countries['PT']['postcode']['class'] = 'form-row-first'; | |
$countries['PT']['city']['class'] = 'form-row-last'; | |
} | |
} | |
} | |
} | |
return $countries; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment