自定义WooCommerce登录表单用户字段 [英] Customize WooCommerce login form user fields

查看:151
本文介绍了自定义WooCommerce登录表单用户字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在woocommerce登录表单中添加一个占位符.

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

以此为起点: woocommerce添加占位符文本以编辑帐户表单:

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.

推荐答案

myaccount/form-login.php模板文件中,对登录字段进行了硬编码添加占位符的唯一方法到这些字段,则需要通过活动的子主题覆盖相关模板(或活动主题)

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)

一旦您复制了位于WooCommerce插件中模板"下的myaccount/form-login.php模板文件,文件夹到(如模板中所述):

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.

打开/编辑form-login.php复制的文件,并将其添加到所有所需的<input> html标签:

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

placeholder="placeholder text"

例如从38行到45行替换为以下内容:

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:

相关线程:

  • 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

这篇关于自定义WooCommerce登录表单用户字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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