我正在设计我在woocommerce checkout-form中选择的字段,虽然有些工作正常,但与帐户相关的字段无法正常工作。 我从this回答了我的帮助,但仍然没有正确加载帐户字段。
我正在使用此代码在form-billing.php中生成这些字段
woocommerce_form_field( 'account_username', $checkout->checkout_fields['account']['account_username'],
$checkout->get_value( 'account_username') );
woocommerce_form_field( 'account_password', $checkout->checkout_fields['account']['account_password'],
$checkout->get_value( 'account_password') );
woocommerce_form_field( 'account_password-2', $checkout->checkout_fields['account']['account_password-2'], $checkout->get_value( 'account_password-2') );
任何帮助将不胜感激。 :)
答案 0 :(得分:0)
我想出了我的问题的答案,我在我的主题function.php中添加了过滤器custom_override,然后制作了我需要的3个字段,即用户名,密码和密码-2,并在我的表单中简单地调用它 - billing.php < / p>
将此代码添加到我的 functions.php
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['account']['account_username'] = array(
'label' => __('Username', 'woocommerce'),
'placeholder' => _x('username', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
$fields['account']['account_password'] = array(
'type' => 'password',
'required' => true,
'label' => __('Account password', 'woocommerce'),
'placeholder' => _x('Password', 'placeholder', 'woocommerce'),
'class' => array('form-row-wide')
);
$fields['account']['account_password-2'] = array(
'type' => 'password',
'required' => true,
'label' => __('Confirm your password', 'woocommerce'),
'placeholder' => _x('Re-password', 'placeholder', 'woocommerce'),
'class' => array('form-row-wide')
);
return $fields;
}
然后在 form-billing.php
中调用我的字段woocommerce_form_field( 'account_username', $checkout->checkout_fields['account']['account_username'],
$checkout->get_value( 'account_username') );
woocommerce_form_field( 'account_password', $checkout->checkout_fields['account']['account_password'], $checkout->get_value( 'account_password') );
woocommerce_form_field( 'account_password-2', $checkout->checkout_fields['account']['account_password-2'], $checkout->get_value( 'account_password-2') );
注意:我在form-billing.php
中的此循环上覆盖了这一行<?php foreach ( $checkout->checkout_fields['billing'] as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
它解决了我的问题,可能对你有所帮助:))