woocommerce-account-fields
create-account
account_username
account_password
billing_email
account_username
add_action( 'woocommerce_form_field_text','XYZ_checkout_custom_heading', 10, 2 );
function XYZ_checkout_custom_heading( $field, $key ){
if ( is_checkout() && ( $key == 'billing_email') ) {
$field .= '<div id="add_custom_heading"><h3>' . __('MY CUSTOM HEADING') . '</h3></div>';
}
return $field;
}
key == 'account_username
If I understood it correctly, that location is above "create account" area.
If that's the case, you can use action hook woocommerce_before_checkout_registration_form
add_action( 'woocommerce_before_checkout_registration_form','XYZ_checkout_custom_heading');
function XYZ_checkout_custom_heading( ){
echo '<div id="add_custom_heading"><h3>' . __('MY CUSTOM HEADING') . '</h3></div>';
}
You can still use woocommerce_form_field_text
but you should not use $field .= <heading>
. But instead, use $field = <heading> . $field
. This way, your heading is added at the top. Not at the bottom. It's like field + heading
when you're doing $field .= <heading>
but heading + field
with $field = <heading> . $field
add_action( 'woocommerce_form_field_text','XYZ_checkout_custom_heading', 10, 2 );
function XYZ_checkout_custom_heading( $field, $key ){
if ( is_checkout() && ( $key == 'account_username') ) {
$field = '<div id="add_custom_heading"><h3>' . __('MY CUSTOM HEADING') . '</h3></div>' . $field;
}
return $field;
}
also note of $key == 'account_username'
.