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

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

问题描述

我想在 woocommerce 登录表单中包含一个占位符.

以这个为起点:


相关主题:

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.

解决方案

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 登录表单用户字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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