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

时间:2021-02-10 05:47:34

标签: php wordpress templates woocommerce email-notifications

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

我检查了负责输出帐单和运输字段的文件 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; ?>

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

1 个答案:

答案 0 :(得分:2)

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

它包含在 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 StackOverFlow