2
votes

I am trying to change the order of the customer details fields displayed in the Woocommerce mail sent to both customer and admin after purchase (table name: addresses).

I checked the file responsible of outputting the billing & shipping fields which is plugins/woocommerce/templates/email-customer-details.php but the customer details are outputted only through a foreach loop and the variable $fields is not even there.

<?php foreach ( $fields as $field ) : ?>
  <li><strong><?php echo wp_kses_post( $field['label'] ); ?>:</strong> <span class="text"><?php echo wp_kses_post( $field['value'] ); ?></span></li>
<?php endforeach; ?>

So, where to change the order of the fields? In particular, I'd like to display the state before the zipcode.

1

1 Answers

2
votes

There is an available filter hook for that.

It's included in WC_Emails customer_details() method, which is used to call the template email-customer-details.php on all related main email templates.

You can use it this way (where $fields is the array of fields that you want to sort):

add_filter( 'woocommerce_email_customer_details_fields', 'filter_email_customer_details_fields', 10, 3 );
function filter_email_customer_details_fields( $fields, $sent_to_admin, $order ) {
    // Do something

    return $fields;
}

For usage, see those related on StackOverFlow