Customize Address States got display error
-
WC: 3.3.1
WP: 4.9.4After update to WC 3.3.0, the address status in billing address and shipping address cannot display currently.
I use add_filter( ‘woocommerce_states’, ‘custom_woocommerce_states’ ); to update a states,
in my account / backend order / order email, all states display in value instead of the display name for the WPML transalation, i.e.
“TSEUNGKWANO” => __(“Tseung Kwan O”, “theme_pan”),
It display “TSEUNGKWANO” instead of translation of “Tseung Kwan O”
But when you resave the address for it, it will display back correctly (but email cannot resave), is there any missing when working on it, please help, thanks
-
If you remove your custom code and filter, does the issue still occur?
And if not, could you post all your custom code here, wrapped in code tags?
Hi
When i remove it, when i choose Hong Kong Island (States), it display Hong Kong (Country), and when I resave it, it will show back Hong Kong Island.
I have done 2 filter related to billing / shipping address:
// Remove fields in Billing / Shipping address on checkout page function project_override_checkout_fields( $fields ) { unset($fields['billing']['billing_company']); unset($fields['billing']['billing_city']); unset($fields['billing']['billing_postcode']); unset($fields['billing']['billing_country']); unset($fields['shipping']['shipping_company']); unset($fields['shipping']['shipping_city']); unset($fields['shipping']['shipping_postcode']); unset($fields['shipping']['shipping_country']); // reorder the fields in checkout $order = array( "billing_first_name", "billing_last_name", "billing_email", "billing_phone", "billing_address_1", "billing_address_2", "billing_state" ); foreach($order as $field) { $ordered_fields[$field] = $fields["billing"][$field]; } $fields["billing"] = $ordered_fields; return $fields; } add_filter( 'woocommerce_checkout_fields' , 'project_override_checkout_fields' ); // Remove fields in my account page function project_override_myaccount_form_fields($fields) { unset( $fields ['company'] ); unset( $fields ['city'] ); unset( $fields ['postcode'] ); unset( $fields ['country'] ); return $fields; } add_filter( 'woocommerce_default_address_fields', 'project_override_myaccount_form_fields' ); // overwrite HK status function custom_woocommerce_states( $states ) { $states['HK'] = array( "NORTHPOINT" => __("North Point", "theme_pan"), "POKFULAM" => __("Pok Fu Lam", "theme_pan"), "CHAIWAN" => __("Chai Wan", "theme_pan"), "WAHFU" => __("Wah Fu", "theme_pan"), "WONGCHUKHAN" => __("Wong Chuk Han", "theme_pan"), "ARTHUREDWARDKENNEDY" => __("Arthur Edward Kennedy", "theme_pan"), "ADMIRALTY" => __("Admiralty", "theme_pan"), "HAPPYVALLEY" => __("Happy Valley", "theme_pan"), "SHEUNGWAN" => __("Sheung Wan", "theme_pan"), "SHAUKEIWAN" => __("Shau Kei Wan", "theme_pan"), "TAIKOO" => __("Tai Koo", "theme_pan"), "CAUSEWAYBAY" => __("Causeway Bay", "theme_pan"), "WANCHAI" => __("WanChai", "theme_pan"), "SAIWAN" => __("Sai Wan", "theme_pan"), "SAIWANHO" => __("Sai Wan Ho", "theme_pan"), "ABERDEEN" => __("Aberdeen", "theme_pan"), "SIUSAIWAN" => __("Siu Sai Wan", "theme_pan"), "APLEICHAU" => __("Ap Lei Chau", "theme_pan"), "QUARRYBAY" => __("Quarry Bay", "theme_pan"), "CENTRAL" => __("Central", "theme_pan"), "STANLEY" => __("Stanley", "theme_pan"), "TAITAM" => __("Tai Tam", "theme_pan"), "REPULSEBAY" => __("Repulse Bay", "theme_pan"), "DEEPWATERBAY" => __("Deep Water Bay", "theme_pan"), "SHEKO" => __("Shek O", "theme_pan"), "CYBERPORT" => __("Cyberport", "theme_pan"), "CHOIHUNG" => __("Choi Hung", "theme_pan"), "CHEUNGSHAWAN" => __("Cheung Sha Wan", "theme_pan"), "TSZWANSHAN" => __("Tsz Wan Shan", "theme_pan"), "TAIKOKTSUI" => __("Tai Kok Tsui", "theme_pan"), "KWUNTONG" => __("Kwun Tong", "theme_pan"), "HOMANTIN" => __("Ho Man Tin", "theme_pan"), "HUNGHOM" => __("Hung Hom", "theme_pan"), "WONGTAISIN" => __("Wong Tai Sin", "theme_pan"), "TSIMSHATSUI" => __("Tsim Sha Tsui", "theme_pan"), "KOWLOONCITY" => __("Kowloon City", "theme_pan"), "KOWLOONTONG" => __("Kowloon Tong", "theme_pan"), "KOWLOONBAY" => __("Kowloon Bay", "theme_pan"), "LAMTIN" => __("Lam Tin", "theme_pan"), "LOKFU" => __("Lok Fu", "theme_pan"), "LAICHIKOK" => __("Lai Chi Kok", "theme_pan"), "MATAUWAI" => __("Ma Tau Wai", "theme_pan"), "MEIFOO" => __("Mei Foo", "theme_pan"), "NGAUCHIWAN" => __("Ngau Chi Wan", "theme_pan"), "NGAUTAUKOK" => __("Ngau Tau Kok", "theme_pan"), "SHAMSHUIPO" => __("Sham Shui Po", "theme_pan"), "SHEKKIPMEI" => __("Shek Kip Mei", "theme_pan"), "SHUNLEE" => __("Shun Lee", "theme_pan"), "PRINCEEDWARD" => __("Prince Edward", "theme_pan"), "TOKWAWAN" => __("To Kwa Wan", "theme_pan"), "MONGKOK" => __("Mong Kok", "theme_pan"), "SANPOKONG" => __("San Po Kong", "theme_pan"), "SAUMAUPING" => __("Sau Mau Ping", "theme_pan"), "YAUMATEI" => __("Yau Ma Tei", "theme_pan"), "YAUTONG" => __("Yau Tong", "theme_pan"), "DIAMONDHILL" => __("Diamond Hill", "theme_pan"), "JORDAN" => __("Jordan", "theme_pan"), return $states; } add_filter( 'woocommerce_states', 'custom_woocommerce_states' );Here is a screenshot on the issue
1. address after take order (they are same as email)
https://screenshot.net/8ymkwbw2. open “edit” the address but without edit any and click update to save again
https://screenshot.net/dozv0i63. address display change to correct display
https://screenshot.net/ldpxqa9Hi,
Anyone have check this issue?
I just follow here:
https://docs.woocommerce.com/document/addmodify-states/And use WPML __() instead
In both frontend and backend, it cannot load the translated states text correct, instead, it load the value of it, and we need to do a “resave” in the order to fix it (either in My Account or Orders in admin panel)
1. the address after the order created.
https://screenshot.net/472r0fd2. open the edit, you can see the translation work correctly in the dropdown list
https://screenshot.net/115n6fo
https://screenshot.net/ymy1kig3. update the order and the translation text come out
https://screenshot.net/5nqokfe4. frontend in my account address
with edit and resave
https://screenshot.net/n62nyigwithout edit and resave
https://screenshot.net/oqv3paj
The topic ‘Customize Address States got display error’ is closed to new replies.