Customize WooCommerce login form user fields

无人久伴 提交于 2020-08-09 10:53:06

问题


I would like to include a placeholder in the woocommerce login form.

Looking at this for a starting point: woocommerce add placeholder text to edit account form:

add_filter( 'woocommerce_form_field_args', 'custom_form_field_args',      10, 3 );
function custom_form_field_args( $args, $key, $value ) { 
   if ( $args['id'] == 'username' ) {
      $args['placeholder'] = 'My placeholder text';
   }

   return $args;
};

Not working as it is. Open to any suggestions.


回答1:


As the login fields are hard coded in myaccount/form-login.php template file, the only way to add placeholder(s) to those fields, requires overriding the related template via the active child theme (or active theme)

Once you have copied the myaccount/form-login.php template file located in WooCommerce plugin under the "templates" folder to (as explained on the template):

<?php
/**
 * Login Form
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/myaccount/form-login.php.

Open/Edit form-login.php copied file, and add to all desired <input> html tags:

placeholder="placeholder text"

Like for example replacing from line 38 to 45 with the following:

        <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
            <label for="username"><?php esc_html_e( 'Username or email address', 'woocommerce' ); ?>&nbsp;<span class="required">*</span></label>
            <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="username" placeholder="<?ph esc_html_e("Here type your Username (or email address)"); ?>" autocomplete="username" value="<?php echo ( ! empty( $_POST['username'] ) ) ? esc_attr( wp_unslash( $_POST['username'] ) ) : ''; ?>" /><?php // @codingStandardsIgnoreLine ?>
        </p>
        <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
            <label for="password"><?php esc_html_e( 'Password', 'woocommerce' ); ?>&nbsp;<span class="required">*</span></label>
            <input class="woocommerce-Input woocommerce-Input--text input-text" type="password" name="password" id="password" placeholder="<?ph esc_html_e(""Here type your password"); ?>" autocomplete="current-password" />
        </p>

Then save… You will get something like:


Related threads:

  • WooCommerce condition for is_account_page(), but only the login portion
  • Add a field to Woocommerce registration form and in admin edit user
  • Sync additional Billing registration fields with default Wordpress fields in WooCommerce


来源:https://stackoverflow.com/questions/57340779/customize-woocommerce-login-form-user-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!