WooCommerce 在另一页丢失密码表单
WooCommerce lost password form on another page
使用最新版本的 WooCommerce,我试图让丢失的密码表单显示在几个不同的页面上。问题是,从 woocommerce > templates > myaccount > form-lost-password.php
复制默认表单并将代码放在另一个页面上是行不通的。
这是表单的默认代码:
<form method="post" class="lost_reset_password">
<?php if( 'lost_password' == $args['form'] ) : ?>
<p><?php echo apply_filters( 'woocommerce_lost_password_message', __( 'Lost your password? Please enter your username or email address. You will receive a link to create a new password via email.', 'woocommerce' ) ); ?></p>
<p class="form-row form-row-first"><label for="user_login"><?php _e( 'Username or email', 'woocommerce' ); ?></label> <input class="input-text" type="text" name="user_login" id="user_login" /></p>
<?php else : ?>
<p><?php echo apply_filters( 'woocommerce_reset_password_message', __( 'Enter a new password below.', 'woocommerce') ); ?></p>
<p class="form-row form-row-first">
<label for="password_1"><?php _e( 'New password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="input-text" name="password_1" id="password_1" />
</p>
<p class="form-row form-row-last">
<label for="password_2"><?php _e( 'Re-enter new password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="input-text" name="password_2" id="password_2" />
</p>
<input type="hidden" name="reset_key" value="<?php echo isset( $args['key'] ) ? $args['key'] : ''; ?>" />
<input type="hidden" name="reset_login" value="<?php echo isset( $args['login'] ) ? $args['login'] : ''; ?>" />
<?php endif; ?>
<div class="clear"></div>
<p class="form-row">
<input type="hidden" name="wc_reset_password" value="true" />
<input type="submit" class="button" value="<?php echo 'lost_password' == $args['form'] ? __( 'Reset Password', 'woocommerce' ) : __( 'Save', 'woocommerce' ); ?>" />
</p>
<?php wp_nonce_field( $args['form'] ); ?>
</form>
这是我正在使用的:
<form method="post" class="lost_reset_password">
<h2 id="reset-h2">Recover your password</h2>
<p id="reset-p">Please enter your email address below to receive a link where you can create a new password</p>
<input class="input-text reset-email-password" type="text" name="user_login" id="user_login" placeholder="Enter your email"/>
<input type="hidden" name="wc_reset_password" value="true" />
<input type="submit" class="button submit-button custom-reset" value="<?php _e( 'Reset Password', 'woocommerce' ); ?>" />
<a href="#" id="reset-back">Back</a>
<?php wp_nonce_field( $args['form'] ); ?>
</form>
请注意,我删除了 else
部分,因为我只希望用户提交的表单收到一封带有 link 的电子邮件以重置他们的密码(这显然会将您带到代码我已经删除了)。
我唯一能想到为什么这不起作用是因为我错过了像 <?php do_action( 'woocommerce_login_form_end' ); ?>
这样的操作,但我不知道丢失密码需要什么操作。
很想在这方面得到一些帮助,所以如果我需要提供其他任何东西,请告诉我,谢谢!
尝试将这行代码插入模板文件中您希望表单显示的位置:
wc_get_template( 'myaccount/form-lost-password.php', array( 'form' => 'lost_password' ) );
这可能是一个老问题,我 运行 遇到了同样的问题,但接受的答案只会显示丢失的密码表单。提交您的电子邮件地址后,它将返回到位于 my-account/lost-password
.
中的默认表单
就我而言,我想删除默认 lost password
页面或端点并使用我的自定义页面,但我仍想使用默认表单。
因此,要在另一页中完整显示lost password form
、confirmation message
和new password form
;
1: 删除丢失密码的端点。
转到 WooCoommerce
> Settings
> Advanced
,然后滚动到 Account endpoints
,您将看到 Lost password
。只需删除它的值并保存设置。
2:将默认丢失密码的URL更改为新的丢失密码页面。
将下面的挂钩添加到您的 functions.php
,注意 /password-recovery
,根据您新的丢失密码页面的 slug 更改它..
function wdm_lostpassword_url() {
return site_url( '/password-recovery' );
}
add_filter( 'lostpassword_url', 'wdm_lostpassword_url', 10, 0 );
3: 设置修改密码成功后重定向到哪里
在我的例子中,我想将用户重定向到 sign-in
页面并添加一条通知消息,表明 he/she 已成功更改密码。使用下面的挂钩根据您的情况更改它,但是无论您设置什么 url,请务必像我所做的那样在 url 的末尾添加 new-password-created=true
的查询在 "/sign-in/?new-password-created=true"
.
function woocommerce_new_pass_redirect( $user ) {
wc_add_notice( __( 'Your password has been changed successfully! Please login to continue.', 'woocommerce' ), 'success' );
wp_redirect( home_url() . "/sign-in/?new-password-created=true" );
exit;
}
add_action( 'woocommerce_customer_reset_password', 'woocommerce_new_pass_redirect' );
4: 为丢失密码表单创建简码。
这就是奇迹发生的地方,使用下面的代码为 lost password form
创建简码。 WooCoommerce 的默认形式仍在使用。
//Create shortcode for lost password form [lost_password_form]
function wc_custom_lost_password_form( $atts ) {
if ( !empty( $_COOKIE[ "csx-reset-link-set" ] ) && isset( $_COOKIE[ "csx-reset-link-set" ] ) && $_COOKIE[ "csx-reset-link-set" ] === "true" ) { // WPCS: input var ok, CSRF ok.
return wc_get_template( 'myaccount/lost-password-confirmation.php' );
} elseif ( !empty( $_SESSION[ "csx-show-reset-form" ] ) && isset( $_SESSION[ "csx-show-reset-form" ] ) && $_SESSION[ "csx-show-reset-form" ] === "true" ) {
$rp_id = $_SESSION[ "csx-id" ];
$rp_key = $_SESSION[ "csx-key" ];
if ( isset( $_COOKIE[ 'wp-resetpass-' . COOKIEHASH ] ) && 0 < strpos( $_COOKIE[ 'wp-resetpass-' . COOKIEHASH ], ':' ) ) { // @codingStandardsIgnoreLine
list( $rp_id, $rp_key ) = array_map( 'wc_clean', explode( ':', wp_unslash( $_COOKIE[ 'wp-resetpass-' . COOKIEHASH ] ), 2 ) ); // @codingStandardsIgnoreLine
$userdata = get_userdata( absint( $rp_id ) );
$rp_login = $userdata ? $userdata->user_login : '';
$user = WC_Shortcode_My_Account::check_password_reset_key( $rp_key, $rp_login );
// Reset key / login is correct, display reset password form with hidden key / login values.
if ( is_object( $user ) ) {
return wc_get_template(
'myaccount/form-reset-password.php',
array(
'key' => $rp_key,
'login' => $rp_login,
)
);
}
}
}
// Show lost password form by default.
return wc_get_template(
'myaccount/form-lost-password.php',
array(
'form' => 'lost_password',
)
);
}
add_shortcode( 'lost_password_form', 'wc_custom_lost_password_form' );
//Handling query
function csx_process_query() {
if ( isset( $_GET[ 'reset-link-sent' ] ) && $_GET[ 'reset-link-sent' ] === "true" ) {
setcookie( 'csx-reset-link-set', "true", time() + ( 300 * 1 ), "/" ); //Allow to submit email for reset after 5 minutes only.
unset( $_SESSION[ "csx-show-reset-form" ] );
}
if ( isset( $_GET[ 'show-reset-form' ] ) && $_GET[ 'show-reset-form' ] === "true" ||
isset( $_GET[ 'key' ] ) && isset( $_GET[ 'id' ] ) ) {
$_SESSION[ "csx-show-reset-form" ] = "true";
setcookie( 'csx-reset-link-set', "", time() - 3600, "/" );
}
//Set session and cookie if key and id are existed
if ( isset( $_GET[ 'key' ] ) && isset( $_GET[ 'id' ] ) ) {
$_SESSION[ "csx-key" ] = $_GET[ 'key' ];
$_SESSION[ "csx-id" ] = $_GET[ 'id' ];
$value = sprintf( "%s:%s", wp_unslash( $_GET[ 'id' ] ), wp_unslash( $_GET[ 'key' ] ) );
WC_Shortcode_My_Account::set_reset_password_cookie( $value );
}
//Unset session and cookie after successfully changed the password.
if ( isset( $_GET[ 'new-password-created' ] ) && $_GET[ 'new-password-created' ] === "true" ) {
setcookie( 'wp-resetpass-' . COOKIEHASH, "", time() - 3600 );
unset( $_SESSION[ "csx-show-reset-form" ] );
unset( $_SESSION[ "csx-reset-link-set" ] );
unset( $_SESSION[ "csx-id" ] );
unset( $_SESSION[ "csx-key" ] );
}
}
add_action( 'init', 'csx_process_query' );
//Redirect to custom lost password on request
function csx_redirections() {
if ( isset( $_GET[ 'reset-link-sent' ] ) || isset( $_GET[ 'show-reset-form' ] ) ||
isset( $_GET[ 'key' ] ) && isset( $_GET[ 'id' ] ) ) {
wp_redirect( home_url() . '/password-recovery' );
exit;
}
}
add_action( 'template_redirect', 'csx_redirections' );
您现在可以使用短代码 [lost_password_form]
,只需将其放入您的页面,表格就会显示出来。请注意,您需要更改 password-recovery
.
的 slug
5: 更改当用户请求找回密码时发送给用户的电子邮件信息中的URL。
覆盖 templates 位于 woocommerce/templates/emails/customer-reset-password.php
和 woocommerce/templates/emails/plain/customer-reset-password.php
.
这是一个普通电子邮件的示例;
<?php
/**
* Customer Reset Password email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/plain/customer-reset-password.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/
* @package WooCommerce/Templates/Emails/Plain
* @version 3.7.0
*/
defined( 'ABSPATH' ) || exit;
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
echo esc_html( wp_strip_all_tags( $email_heading ) );
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
/* translators: %s: Customer username */
echo sprintf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $user_login ) ) . "\n\n";
/* translators: %s: Store name */
echo sprintf( esc_html__( 'Someone has requested a new password for the following account on %s:', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ) . "\n\n";
/* translators: %s: Customer username */
echo sprintf( esc_html__( 'Username: %s', 'woocommerce' ), esc_html( $user_login ) ) . "\n\n";
echo esc_html__( 'If you didn\'t make this request, just ignore this email. If you\'d like to proceed:', 'woocommerce' ) . "\n\n";
echo esc_url( add_query_arg( array( 'key' => $reset_key, 'id' => $user_id ), home_url().'/your-custom-url/' ) ) . "\n\n"; // phpcs:ignore
echo "\n\n----------------------------------------\n\n";
/**
* Show user-defined additional content - this is set in each email's settings.
*/
if ( $additional_content ) {
echo esc_html( wp_strip_all_tags( wptexturize( $additional_content ) ) );
echo "\n\n----------------------------------------\n\n";
}
对于非普通电子邮件;
<?php
/**
* Customer Reset Password email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-reset-password.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/
* @package WooCommerce/Templates/Emails
* @version 4.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
?>
<?php do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<?php /* translators: %s: Customer username */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $user_login ) ); ?></p>
<?php /* translators: %s: Store name */ ?>
<p><?php printf( esc_html__( 'Someone has requested a new password for the following account on %s:', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p>
<?php /* translators: %s: Customer username */ ?>
<p><?php printf( esc_html__( 'Username: %s', 'woocommerce' ), esc_html( $user_login ) ); ?></p>
<p><?php esc_html_e( 'If you didn\'t make this request, just ignore this email. If you\'d like to proceed:', 'woocommerce' ); ?></p>
<p>
<a class="link" href="<?php
echo esc_url( add_query_arg( array( 'key' => $reset_key, 'id' => $user_id ), home_url()."/your-custom-url/" ) ); ?>"><?php // phpcs:ignore ?>
<?php esc_html_e( 'Click here to reset your password', 'woocommerce' ); ?>
</a>
</p>
<?php
/**
* Show user-defined additional content - this is set in each email's settings.
*/
if ( $additional_content ) {
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
}
do_action( 'woocommerce_email_footer', $email );
只需将 url 更改为您的页面。请注意,您需要在普通和非普通电子邮件中都这样做。
使用最新版本的 WooCommerce,我试图让丢失的密码表单显示在几个不同的页面上。问题是,从 woocommerce > templates > myaccount > form-lost-password.php
复制默认表单并将代码放在另一个页面上是行不通的。
这是表单的默认代码:
<form method="post" class="lost_reset_password">
<?php if( 'lost_password' == $args['form'] ) : ?>
<p><?php echo apply_filters( 'woocommerce_lost_password_message', __( 'Lost your password? Please enter your username or email address. You will receive a link to create a new password via email.', 'woocommerce' ) ); ?></p>
<p class="form-row form-row-first"><label for="user_login"><?php _e( 'Username or email', 'woocommerce' ); ?></label> <input class="input-text" type="text" name="user_login" id="user_login" /></p>
<?php else : ?>
<p><?php echo apply_filters( 'woocommerce_reset_password_message', __( 'Enter a new password below.', 'woocommerce') ); ?></p>
<p class="form-row form-row-first">
<label for="password_1"><?php _e( 'New password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="input-text" name="password_1" id="password_1" />
</p>
<p class="form-row form-row-last">
<label for="password_2"><?php _e( 'Re-enter new password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="input-text" name="password_2" id="password_2" />
</p>
<input type="hidden" name="reset_key" value="<?php echo isset( $args['key'] ) ? $args['key'] : ''; ?>" />
<input type="hidden" name="reset_login" value="<?php echo isset( $args['login'] ) ? $args['login'] : ''; ?>" />
<?php endif; ?>
<div class="clear"></div>
<p class="form-row">
<input type="hidden" name="wc_reset_password" value="true" />
<input type="submit" class="button" value="<?php echo 'lost_password' == $args['form'] ? __( 'Reset Password', 'woocommerce' ) : __( 'Save', 'woocommerce' ); ?>" />
</p>
<?php wp_nonce_field( $args['form'] ); ?>
</form>
这是我正在使用的:
<form method="post" class="lost_reset_password">
<h2 id="reset-h2">Recover your password</h2>
<p id="reset-p">Please enter your email address below to receive a link where you can create a new password</p>
<input class="input-text reset-email-password" type="text" name="user_login" id="user_login" placeholder="Enter your email"/>
<input type="hidden" name="wc_reset_password" value="true" />
<input type="submit" class="button submit-button custom-reset" value="<?php _e( 'Reset Password', 'woocommerce' ); ?>" />
<a href="#" id="reset-back">Back</a>
<?php wp_nonce_field( $args['form'] ); ?>
</form>
请注意,我删除了 else
部分,因为我只希望用户提交的表单收到一封带有 link 的电子邮件以重置他们的密码(这显然会将您带到代码我已经删除了)。
我唯一能想到为什么这不起作用是因为我错过了像 <?php do_action( 'woocommerce_login_form_end' ); ?>
这样的操作,但我不知道丢失密码需要什么操作。
很想在这方面得到一些帮助,所以如果我需要提供其他任何东西,请告诉我,谢谢!
尝试将这行代码插入模板文件中您希望表单显示的位置:
wc_get_template( 'myaccount/form-lost-password.php', array( 'form' => 'lost_password' ) );
这可能是一个老问题,我 运行 遇到了同样的问题,但接受的答案只会显示丢失的密码表单。提交您的电子邮件地址后,它将返回到位于 my-account/lost-password
.
就我而言,我想删除默认 lost password
页面或端点并使用我的自定义页面,但我仍想使用默认表单。
因此,要在另一页中完整显示lost password form
、confirmation message
和new password form
;
1: 删除丢失密码的端点。
转到 WooCoommerce
> Settings
> Advanced
,然后滚动到 Account endpoints
,您将看到 Lost password
。只需删除它的值并保存设置。
2:将默认丢失密码的URL更改为新的丢失密码页面。
将下面的挂钩添加到您的 functions.php
,注意 /password-recovery
,根据您新的丢失密码页面的 slug 更改它..
function wdm_lostpassword_url() {
return site_url( '/password-recovery' );
}
add_filter( 'lostpassword_url', 'wdm_lostpassword_url', 10, 0 );
3: 设置修改密码成功后重定向到哪里
在我的例子中,我想将用户重定向到 sign-in
页面并添加一条通知消息,表明 he/she 已成功更改密码。使用下面的挂钩根据您的情况更改它,但是无论您设置什么 url,请务必像我所做的那样在 url 的末尾添加 new-password-created=true
的查询在 "/sign-in/?new-password-created=true"
.
function woocommerce_new_pass_redirect( $user ) {
wc_add_notice( __( 'Your password has been changed successfully! Please login to continue.', 'woocommerce' ), 'success' );
wp_redirect( home_url() . "/sign-in/?new-password-created=true" );
exit;
}
add_action( 'woocommerce_customer_reset_password', 'woocommerce_new_pass_redirect' );
4: 为丢失密码表单创建简码。
这就是奇迹发生的地方,使用下面的代码为 lost password form
创建简码。 WooCoommerce 的默认形式仍在使用。
//Create shortcode for lost password form [lost_password_form]
function wc_custom_lost_password_form( $atts ) {
if ( !empty( $_COOKIE[ "csx-reset-link-set" ] ) && isset( $_COOKIE[ "csx-reset-link-set" ] ) && $_COOKIE[ "csx-reset-link-set" ] === "true" ) { // WPCS: input var ok, CSRF ok.
return wc_get_template( 'myaccount/lost-password-confirmation.php' );
} elseif ( !empty( $_SESSION[ "csx-show-reset-form" ] ) && isset( $_SESSION[ "csx-show-reset-form" ] ) && $_SESSION[ "csx-show-reset-form" ] === "true" ) {
$rp_id = $_SESSION[ "csx-id" ];
$rp_key = $_SESSION[ "csx-key" ];
if ( isset( $_COOKIE[ 'wp-resetpass-' . COOKIEHASH ] ) && 0 < strpos( $_COOKIE[ 'wp-resetpass-' . COOKIEHASH ], ':' ) ) { // @codingStandardsIgnoreLine
list( $rp_id, $rp_key ) = array_map( 'wc_clean', explode( ':', wp_unslash( $_COOKIE[ 'wp-resetpass-' . COOKIEHASH ] ), 2 ) ); // @codingStandardsIgnoreLine
$userdata = get_userdata( absint( $rp_id ) );
$rp_login = $userdata ? $userdata->user_login : '';
$user = WC_Shortcode_My_Account::check_password_reset_key( $rp_key, $rp_login );
// Reset key / login is correct, display reset password form with hidden key / login values.
if ( is_object( $user ) ) {
return wc_get_template(
'myaccount/form-reset-password.php',
array(
'key' => $rp_key,
'login' => $rp_login,
)
);
}
}
}
// Show lost password form by default.
return wc_get_template(
'myaccount/form-lost-password.php',
array(
'form' => 'lost_password',
)
);
}
add_shortcode( 'lost_password_form', 'wc_custom_lost_password_form' );
//Handling query
function csx_process_query() {
if ( isset( $_GET[ 'reset-link-sent' ] ) && $_GET[ 'reset-link-sent' ] === "true" ) {
setcookie( 'csx-reset-link-set', "true", time() + ( 300 * 1 ), "/" ); //Allow to submit email for reset after 5 minutes only.
unset( $_SESSION[ "csx-show-reset-form" ] );
}
if ( isset( $_GET[ 'show-reset-form' ] ) && $_GET[ 'show-reset-form' ] === "true" ||
isset( $_GET[ 'key' ] ) && isset( $_GET[ 'id' ] ) ) {
$_SESSION[ "csx-show-reset-form" ] = "true";
setcookie( 'csx-reset-link-set', "", time() - 3600, "/" );
}
//Set session and cookie if key and id are existed
if ( isset( $_GET[ 'key' ] ) && isset( $_GET[ 'id' ] ) ) {
$_SESSION[ "csx-key" ] = $_GET[ 'key' ];
$_SESSION[ "csx-id" ] = $_GET[ 'id' ];
$value = sprintf( "%s:%s", wp_unslash( $_GET[ 'id' ] ), wp_unslash( $_GET[ 'key' ] ) );
WC_Shortcode_My_Account::set_reset_password_cookie( $value );
}
//Unset session and cookie after successfully changed the password.
if ( isset( $_GET[ 'new-password-created' ] ) && $_GET[ 'new-password-created' ] === "true" ) {
setcookie( 'wp-resetpass-' . COOKIEHASH, "", time() - 3600 );
unset( $_SESSION[ "csx-show-reset-form" ] );
unset( $_SESSION[ "csx-reset-link-set" ] );
unset( $_SESSION[ "csx-id" ] );
unset( $_SESSION[ "csx-key" ] );
}
}
add_action( 'init', 'csx_process_query' );
//Redirect to custom lost password on request
function csx_redirections() {
if ( isset( $_GET[ 'reset-link-sent' ] ) || isset( $_GET[ 'show-reset-form' ] ) ||
isset( $_GET[ 'key' ] ) && isset( $_GET[ 'id' ] ) ) {
wp_redirect( home_url() . '/password-recovery' );
exit;
}
}
add_action( 'template_redirect', 'csx_redirections' );
您现在可以使用短代码 [lost_password_form]
,只需将其放入您的页面,表格就会显示出来。请注意,您需要更改 password-recovery
.
5: 更改当用户请求找回密码时发送给用户的电子邮件信息中的URL。
覆盖 templates 位于 woocommerce/templates/emails/customer-reset-password.php
和 woocommerce/templates/emails/plain/customer-reset-password.php
.
这是一个普通电子邮件的示例;
<?php
/**
* Customer Reset Password email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/plain/customer-reset-password.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/
* @package WooCommerce/Templates/Emails/Plain
* @version 3.7.0
*/
defined( 'ABSPATH' ) || exit;
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
echo esc_html( wp_strip_all_tags( $email_heading ) );
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
/* translators: %s: Customer username */
echo sprintf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $user_login ) ) . "\n\n";
/* translators: %s: Store name */
echo sprintf( esc_html__( 'Someone has requested a new password for the following account on %s:', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ) . "\n\n";
/* translators: %s: Customer username */
echo sprintf( esc_html__( 'Username: %s', 'woocommerce' ), esc_html( $user_login ) ) . "\n\n";
echo esc_html__( 'If you didn\'t make this request, just ignore this email. If you\'d like to proceed:', 'woocommerce' ) . "\n\n";
echo esc_url( add_query_arg( array( 'key' => $reset_key, 'id' => $user_id ), home_url().'/your-custom-url/' ) ) . "\n\n"; // phpcs:ignore
echo "\n\n----------------------------------------\n\n";
/**
* Show user-defined additional content - this is set in each email's settings.
*/
if ( $additional_content ) {
echo esc_html( wp_strip_all_tags( wptexturize( $additional_content ) ) );
echo "\n\n----------------------------------------\n\n";
}
对于非普通电子邮件;
<?php
/**
* Customer Reset Password email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-reset-password.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/
* @package WooCommerce/Templates/Emails
* @version 4.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
?>
<?php do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<?php /* translators: %s: Customer username */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $user_login ) ); ?></p>
<?php /* translators: %s: Store name */ ?>
<p><?php printf( esc_html__( 'Someone has requested a new password for the following account on %s:', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p>
<?php /* translators: %s: Customer username */ ?>
<p><?php printf( esc_html__( 'Username: %s', 'woocommerce' ), esc_html( $user_login ) ); ?></p>
<p><?php esc_html_e( 'If you didn\'t make this request, just ignore this email. If you\'d like to proceed:', 'woocommerce' ); ?></p>
<p>
<a class="link" href="<?php
echo esc_url( add_query_arg( array( 'key' => $reset_key, 'id' => $user_id ), home_url()."/your-custom-url/" ) ); ?>"><?php // phpcs:ignore ?>
<?php esc_html_e( 'Click here to reset your password', 'woocommerce' ); ?>
</a>
</p>
<?php
/**
* Show user-defined additional content - this is set in each email's settings.
*/
if ( $additional_content ) {
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
}
do_action( 'woocommerce_email_footer', $email );
只需将 url 更改为您的页面。请注意,您需要在普通和非普通电子邮件中都这样做。