Hi Taisho,
I just tested this, and it works based on countries, once I set the base country to Poland then I was able to goto my-account page and set a postal code with dashes like this: https://cld.wthms.co/bOXaif
I am having a hunch that it could be a conflict from your theme or one of the other plugins installed, Can you test by deactivating all plugins except for WooCommerce and switching to the StoreFront theme to check if the behavior persists?
If the issue goes away then activate plugins/theme one by one to check which one is causing the behavior. Also please ensure to update to the latest version of WooCommerce.
Cheers!
Thread Starter
taisho
(@taisho)
Thank You Praveen. I narrowed down where the issue lies and it’s functions.php of my child Storefront theme. I didn’t follow the usual procedure, because it seemed highly unlikely for such error to be caused by any plugin or Storefront, but switching to default Storefront alone showed that it’s my modifications, I have 3 rather popular snippets meddling with addresses and removing any single one doesn’t help. Hopefully I figure out what’s wrong.
Cheers!
-
This reply was modified 6 years, 12 months ago by
taisho.
Thread Starter
taisho
(@taisho)
It came out that because of cache my tests didn’t go correctly. It was only 1 snipped causing problems. You were correct to mention that postcode format change is connected to country. I post a working snippet which is fixed by adding ‘country’ to array, but the thing is that shop is only country-wide and I don’t really want it to be displayed, any ideas for fix? Hiding with CSS is possible for form edit, but in Addresses tab of My Account there is also whole address generated as plain text after <br> and perhaps in other places too, so CSS is not an option.
It’s a shame that in “sell to specific country” I have only Poland selected, Poland is the only country in my shipping zones and still address in My account section won’t allow me to store proper Polish addresses (if user goes in edit mode and saves changes, no matter if anything is actually changed) if I decide not to show country.
add_filter( 'woocommerce_default_address_fields', 'custom_default_address_fields' );
function custom_default_address_fields( $fields ) {
$fields_order = array( 'first_name', 'last_name', 'company', 'address_1', 'postcode', 'city', 'country');
// Set fields priority
$priority = 10;
foreach ( $fields_order as $key ) {
if ( ! isset( $fields[ $key ] ) ) {
continue;
}
$fields[ $key ]['priority'] = $priority;
$priority += 10;
}
// Change fields order
$fields_ordered = array();
foreach ( $fields_order as $key ) {
if ( isset( $fields[ $key ] ) ) {
$fields_ordered[ $key ] = $fields[ $key ];
}
}
return $fields_ordered;
}
-
This reply was modified 6 years, 12 months ago by
taisho.
-
This reply was modified 6 years, 12 months ago by
taisho.