Skip to content

Instantly share code, notes, and snippets.

@webdados
Created July 6, 2023 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdados/67b40cd6fb8396d58c13f7da77949d83 to your computer and use it in GitHub Desktop.
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
<?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