WooCommerce在另一页上丢失了密码表格 [英] WooCommerce lost password form on another page

查看:59
本文介绍了WooCommerce在另一页上丢失了密码表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用最新版本的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部分,是因为我只希望用户提交的表单能收到一封带有链接的电子邮件,以重置其密码(显然,这将带您进入我删除的代码). /p>

我唯一能想到的是为什么它不起作用,是因为我错过了<?php do_action( 'woocommerce_login_form_end' ); ?>之类的操作,但是我不知道丢失密码所需的操作是什么.

很乐意在此方面获得一些帮助,因此,如果需要我提供其他任何信息,请告诉我!

解决方案

尝试将以下代码行插入到要显示表单的模板文件中:

wc_get_template( 'myaccount/form-lost-password.php', array( 'form' => 'lost_password' ) );

Using the latest version of WooCommerce, I'm trying to get the lost password form to show up on several different pages. The problem is, copying the default form from woocommerce > templates > myaccount > form-lost-password.php and placing the code on another page would not work.

Here is the default code for the form:

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

And here's what I'm using:

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

Notice that I stripped the else part because I only want the form where the user submits to get an email with a link to reset their password (which evidently would take you to the code the I've removed).

The only thing that I can think of why this isn't working is because I'm missing the actions like <?php do_action( 'woocommerce_login_form_end' ); ?> but I wouldn't know what the action I need for the lost password is.

Would love to get some help on this so let me know if I need to provide anything else, thanks!

解决方案

Try inserting this line of code into the template file where you want the form to show up:

wc_get_template( 'myaccount/form-lost-password.php', array( 'form' => 'lost_password' ) );

这篇关于WooCommerce在另一页上丢失了密码表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆