首页 > 解决方案 > 将 WordPress 用户后端中创建的附加字段添加到 woocommerce admin-new-order 电子邮件

问题描述

我在下面的代码中创建了一个附加字段,它是我们用来识别客户的内部参考。它由管理员在 WordPress 后端输入,对客户不可见。该字段工作正常,并保存输入该字段的数据。我的问题和我苦苦挣扎的地方是,当客户下订单时,我需要此字段出现在来自 woocomm 的 admin-new-order 电子邮件中。这必须适用于所有下订单的客户。尝试了多种方法,但我无法让该字段出现在电子邮件中,以便管理员可以在下新订单时参考。客户都首先获得批准,并在他们被允许下订单之前将参考添加到他们的个人资料中
您的帮助和意见将不胜感激

 //** Internal Reference **//

 add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
 add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

 function my_show_extra_profile_fields( $user ) { ?>
 <h3>Extra profile information</h3>
 <table class="form-table">
    <tr>
        <th><label for="int_ref">Internal Reference</label></th>
        <td>
            <input type="text" name="int_ref" id="int_ref" value="<?php echo esc_attr( 
 get_the_author_meta( 'int_ref', $user->ID ) ); ?>" class="regular-text" /><br />
        </td>
    </tr>
  </table>
  <?php }

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {
    update_usermeta( $user_id, 'int_ref', sanitize_text_field( $_POST['int_ref']) );
  }

标签: phpwordpresswoocommercehook-woocommerce

解决方案


推荐阅读