WooCommerce更改另一页上的密码表单

时间:2017-10-19 12:42:32

标签: php wordpress forms templates woocommerce

使用最新版本的WooCommerce,我正在尝试将更改密码表单显示在不同页面上。问题是,从woocommerce>复制默认表单。模板> myaccount> form-edit-account.php并将代码放在另一个页面上是行不通的。

这是该模板的原始代码:

<?php


if ( ! defined( 'ABSPATH' ) ) {
exit;
}

do_action( 'woocommerce_before_edit_account_form' ); ?>

<form class="woocommerce-EditAccountForm edit-account" action="" 
method="post">

<?php do_action( 'woocommerce_edit_account_form_start' ); ?>

<p class="woocommerce-form-row woocommerce-form-row--first form-row form-
row-first">
    <label for="account_first_name"><?php _e( 'First name', 'woocommerce' ); 
?> <span class="required">*</span></label>
    <input type="text" class="woocommerce-Input woocommerce-Input--text 
input-text" name="account_first_name" id="account_first_name" value="<?php 
echo esc_attr( $user->first_name ); ?>" />
</p>
<p class="woocommerce-form-row woocommerce-form-row--last form-row form-row-
last">
    <label for="account_last_name"><?php _e( 'Last name', 'woocommerce' ); ?
> <span class="required">*</span></label>
    <input type="text" class="woocommerce-Input woocommerce-Input--text 
 input-text" name="account_last_name" id="account_last_name" value="<?php 
 echo esc_attr( $user->last_name ); ?>" />
</p>
<div class="clear"></div>

<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-
 wide">
    <label for="account_email"><?php _e( 'Email address', 'woocommerce' ); ?
 > <span class="required">*</span></label>
    <input type="email" class="woocommerce-Input woocommerce-Input--email 
 input-text" name="account_email" id="account_email" value="<?php echo 
 esc_attr( $user->user_email ); ?>" />
</p>

<!--<fieldset>
    <legend><?php _e( 'Password change', 'woocommerce' ); ?></legend>

    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-
 row-wide">
        <label for="password_current"><?php _e( 'Current password (leave 
 blank to leave unchanged)', 'woocommerce' ); ?></label>
        <input type="password" class="woocommerce-Input woocommerce-Input--
  password input-text" name="password_current" id="password_current" />
    </p>
    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-
  row-wide">
        <label for="password_1"><?php _e( 'New password (leave blank to leave unchanged)', 'woocommerce' ); ?></label>
        <input type="password" class="woocommerce-Input woocommerce-Input--
   password input-text" name="password_1" id="password_1" />
    </p>
    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
        <label for="password_2"><?php _e( 'Confirm new password', 
 'woocommerce' ); ?></label>
        <input type="password" class="woocommerce-Input woocommerce-Input--
  password input-text" name="password_2" id="password_2" />
    </p>
</fieldset>-->
<div class="clear"></div>

<?php do_action( 'woocommerce_edit_account_form' ); ?>

<p>
    <?php wp_nonce_field( 'save_account_details' ); ?>
    <input type="submit" class="woocommerce-Button button" name="save_account_details" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>" />
    <input type="hidden" name="action" value="save_account_details" />
</p>

<?php do_action( 'woocommerce_edit_account_form_end' ); ?>

所以我的问题是如何在分离的页面中仅显示此代码内容:

<legend><?php _e( 'Password change', 'woocommerce' ); ?></legend>

    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-
row-wide">
        <label for="password_current"><?php _e( 'Current password (leave 
blank to leave unchanged)', 'woocommerce' ); ?></label>
        <input type="password" class="woocommerce-Input woocommerce-Input--
 password input-text" name="password_current" id="password_current" />
    </p>
    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-
 row-wide">
        <label for="password_1"><?php _e( 'New password (leave blank to 
 leave unchanged)', 'woocommerce' ); ?></label>
        <input type="password" class="woocommerce-Input woocommerce-Input--
 password input-text" name="password_1" id="password_1" />
    </p>
    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-
 row-wide">
        <label for="password_2"><?php _e( 'Confirm new password', 
 'woocommerce' ); ?></label>
        <input type="password" class="woocommerce-Input woocommerce-Input--
 password input-text" name="password_2" id="password_2" />
    </p>
</fieldset>

提前致谢!

1 个答案:

答案 0 :(得分:1)

如果我要这样做,我会小心地将该表单删除,然后将其放在侧边栏中的另一个自定义页面模板上,然后将该模板用于您希望它显示的页面。

正如Woo经常使用的那样,有时只要WordPress运行Woo动作,例如<?php do_action( 'woocommerce_edit_account_form_start' ); ?>,它可能会拉动HTML来帮助布局,甚至可以在一些奇怪的情况下加载Javascript。您将需要提取所有“多余”表单信息,使其正常运行,然后在保持功能正常的同时省去所有部分。

希望有所帮助!