自定义 WooCommerce 登录表单用户字段 [英] Customize WooCommerce login form user fields
问题描述
我想在 woocommerce 登录表单中包含一个占位符.
以这个为起点:
相关主题:
- WooCommerce 条件is_account_page(),但只有登录部分
- 添加Woocommerce 注册表和管理员编辑用户的字段
- 同步附加账单WooCommerce 中带有默认 Wordpress 字段的注册字段
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' ); ?> <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' ); ?> <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
这篇关于自定义 WooCommerce 登录表单用户字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!