我正在自定义WooCommerce结帐页面字段.我想在字段之间添加标题(文本).我重新排序了这样的字段
add_filter('woocommerce_checkout_fields', 'ac_checkout_reorder_fields');
function ac_checkout_reorder_fields($fields) {
$order = array(
"billing_first_name",
"billing_last_name",
"billing_company",
"billing_email",
"billing_phone",
"billing_address_1",
"billing_address_2",
"billing_postcode",
"billing_country"
);
foreach($order as $field)
{
$ordered_fields[$field] = $fields["billing"][$field];
}
$fields["billing"] = $ordered_fields;
return $fields;
}
Run Code Online (Sandbox Code Playgroud)
然后我添加了一个这样的新标题
add_action( 'woocommerce_after_checkout_billing_form', 'add_custom_heading' );
function add_custom_heading( $checkout ) {
echo '<div id="add_custom_heading"><h2>' . __('Custom Heading Here') . '</h2></div>' ;
}
Run Code Online (Sandbox Code Playgroud)
现在重新排列字段并显示自定义标题.但我希望标题显示在名称和公司字段的下方.使用我的代码,该字段将在下面添加.我如何在我想要的地方重新定位.
PS:我还尝试使用此挂钩woocommerce_checkout_fields添加占位符并删除标签来添加自定义整个字段部分.以下是代码,但这也无法帮助我解决问题.
function add_wc_custom_fields($fields) {
global $woocommerce;
$countries_obj = new WC_Countries();
$countries = $countries_obj->__get('countries');
$fields['billing']['billing_first_name'] = array(
'label' => '',
'placeholder' => …Run Code Online (Sandbox Code Playgroud)