How to add a heading above woocommerce-account-fields in Woocommerce

廉价感情. 提交于 2019-12-06 09:01:49

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'.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!