在 WooCommerce 电子邮件通知中重新排序客户详细信息

Reorder customer details in WooCommerce email notifications

我正在尝试更改购买后发送给客户和管理员的 Woocommerce 邮件中显示的客户详细信息字段的顺序(table 姓名:地址)。

我检查了负责输出账单和运输字段的文件plugins/woocommerce/templates/email-customer-details.php,但客户详细信息仅通过 foreach 循环输出,变量 $fields 甚至不存在。

<?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; ?>

那么,在哪里更改字段的顺序?特别是,我想在邮政编码之前显示州。

有一个可用的过滤器挂钩。

它包含在 WC_Emails customer_details() method 中,用于在所有相关的主要电子邮件模板上调用模板 email-customer-details.php

您可以这样使用它(其中$fields是您要排序的字段数组):

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;
}

用法,see those related on Whosebug