douci6541 2018-05-16 18:20
浏览 113
已采纳

通过Woocommerce“新帐户”电子邮件通知模板获取用户电子邮件

In Woocommerce I am trying to customize the "New account" email notification template changing the texts.

Currently the default template shows the username but intead I want it to show the user email.

I thought I needed to use something like $user_email but that shows up blank (or empty).

How to get the user email in Woocommerce "New account" email notification template?

That is the customized template that I got where I need to get the user email:

<?php
/**
 * Customer new account email
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-new-account.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author      WooThemes
 * @package     WooCommerce/Templates/Emails
 * @version     1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

?>

<?php do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

    <p><?php printf( __( 'Thanks for creating an account on %1$s. Your registered email is %2$s', 'woocommerce' ), esc_html( $blogname ), '<strong>' . esc_html( $user_email ) . '</strong>' ); ?></p>

<?php if ( 'yes' === get_option( 'woocommerce_registration_generate_password' ) && $password_generated ) : ?>

    <p><?php printf( __( 'Your password has been automatically generated: %s', 'woocommerce' ), '<strong>' . esc_html( $user_pass ) . '</strong>' ); ?></p>

<?php endif; ?>

    <p><?php printf( __( 'You can access your account area to view your orders and change your password here: %s.', 'woocommerce' ), make_clickable( esc_url( wc_get_page_permalink( 'myaccount' ) ) ) ); ?></p>

<?php do_action( 'woocommerce_email_footer', $email );
  • 写回答

1条回答 默认 最新

  • doujiang2643 2018-05-16 23:54
    关注

    In this template, the $user_login is defined and available. What you can do is to use the WordPress function get_user_by() with it to get the user email.

    So in the template you will have just to replace this line:

        <p><?php printf( __( 'Thanks for creating an account on %1$s. Your registered email is %2$s', 'woocommerce' ), esc_html( $blogname ), '<strong>' . esc_html( $user->user_email ) . '</strong>' ); ?></p>
    

    By this instead:

    <?php $user = get_user_by('login', $user_login );
    
    if( $user && isset($user->user_email) ): ?>
    
        <p><?php printf( __( 'Thanks for creating an account on %1$s. Your registered email is %2$s', 'woocommerce' ), esc_html( $blogname ), '<strong>' . esc_html( $user->user_email ) . '</strong>' ); ?></p>
    
    <?php else: ?>
    
        <p><?php printf( __( 'Thanks for creating an account on %1$s. Your username is %2$s', 'woocommerce' ), esc_html( $blogname ), '<strong>' . esc_html( $user_login ) . '</strong>' ); ?></p>
    
    <?php endif; ?>
    

    This way you will be sure to don't get any error and you will have the default woocommerce alternative.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab