Support » Plugin: WooCommerce » New states show up as codes in e-mails

  • Resolved marpessa1


    Hello, I’ve added new states to my website by adding the code to the functions.php of my child theme as suggested here:

    It works fine on front-end, however in order emails (both that are sent to admin and the customer), instead of the name of the newly added state, its code shows up (such as TR87 whereas TR87 actually is the Bagcilar state in functions.php). How can I fix this?

    Thanks in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Thomas Shellberg


    Automattic Happiness Engineer

    I just tested the snippet in that doc and it works fine for me. I created a custom state called ‘New New York'(NNY) and everything displayed properly, both at checkout and in emails:

    I would try testing with a default theme, perhaps your theme has outdated email templates.



    Hello Thomas, thanks for your help. Well that’s the problem, it shows the “code” instead of the value. I would like it to show “New New York” in the e-mails instead of the “NNY” as it does on the frontend state list. Is there any way to achieve this?

    Plugin Support ryanr14


    Hi there,

    I would indeed assume so, but you’ll likely need to modify the appropriate email templates if possible. That’d be true likely even without adding your own state as well. 🙂

    I briefly looked and found that each email uses a 'woocommerce_email_customer_details' action that eventually leads to billing/shipping details fields via <?php echo $order->get_formatted_billing_address(); ?>

    I haven’t gone further than that, as it may take more custom work to show the actual state name compare to just the state code.



    I have one other question;

    How about I use the exact state name instead of the TRXX code?

    Say, if I use it as;
    add_filter( ‘woocommerce_states’, ‘custom_woocommerce_states’ );
    function custom_woocommerce_states( $states ) {
    $states[‘TR’] = array(
    ‘Arnavutköy – Baklalı’ => ‘Arnavutköy – Baklalı’,

    would the empty spaces and Turkish characters create a problem?



    Or, can I use a function that uses the below logic and prints the state name anywhere in the site?

    'formated_state' => WC()->countries->states[$order->get_billing_country()][$order->get_billing_state()], //human readable formated state name

    As in here? Can you help me with that?

    Plugin Support Will Brubaker


    Automattic Happiness Engineer

    can I use a function that uses the below logic and prints the state name anywhere in the site

    No, you couldn’t just print that anywhere on the site as you would need access to the $order object.

    This code produces this result:

    At checkout:

    Thank you page:

    Order email:

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘New states show up as codes in e-mails’ is closed to new replies.