Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce lost password form on another page

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!

like image 249
chdltest Avatar asked Nov 30 '22 00:11

chdltest


1 Answers

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' ) );
like image 168
d79 Avatar answered Dec 04 '22 09:12

d79