我正在尝试为我的WooCommerce结账字段添加占位符,对于每个字段都可以完美地工作,但是电话和电子邮件字段除外。
这是我正在使用的代码:
add_filter('woocommerce_default_address_fields', 'override_address_fields');
function override_address_fields( $address_fields ) {
$address_fields['first_name']['placeholder'] = 'Fornavn';
$address_fields['last_name']['placeholder'] = 'Efternavn';
$address_fields['address_1']['placeholder'] = 'Adresse';
$address_fields['state']['placeholder'] = 'Stat';
$address_fields['postcode']['placeholder'] = 'Postnummer';
$address_fields['city']['placeholder'] = 'By';
$address_fields['phone']['placeholder'] = 'Telefon';
$address_fields['email']['placeholder'] = 'Email';
return $address_fields;
}
我错在哪里了?为什么电话和电子邮件没有输出任何结果?
我使用浏览器开发者工具检查器从这两个字段中获取了ID。
编辑:
我也尝试了建议的代码:
add_filter('woocommerce_checkout_fields', 'override_checkout_fields');
function override_checkout_fields( $checkout_fields ) {
$checkout_fields['first_name']['placeholder'] = 'Fornavn';
$checkout_fields['last_name']['placeholder'] = 'Efternavn';
$checkout_fields['address_1']['placeholder'] = 'Adresse';
$checkout_fields['state']['placeholder'] = 'Stat';
$checkout_fields['postcode']['placeholder'] = 'Postnummer';
$checkout_fields['city']['placeholder'] = 'By';
$checkout_fields['phone']['placeholder'] = 'Telefon';
$checkout_fields['email']['placeholder'] = 'Email';
return $checkout_fields;
}
还有这个:
add_filter('woocommerce_checkout_fields', 'override_checkout_fields');
function override_checkout_fields( $checkout_fields ) {
$checkout_fields['billing_first_name']['placeholder'] = 'Fornavn';
$checkout_fields['billing_last_name']['placeholder'] = 'Efternavn';
$checkout_fields['billing_address_1']['placeholder'] = 'Adresse';
$checkout_fields['billing_state']['placeholder'] = 'Stat';
$checkout_fields['billing_postcode']['placeholder'] = 'Postnummer';
$checkout_fields['billing_city']['placeholder'] = 'By';
$checkout_fields['billing_phone']['placeholder'] = 'Telefon';
$checkout_fields['billing_email']['placeholder'] = 'Email';
return $checkout_fields;
}
但它不起作用。
$fields['account']['account_username']['placeholder'] = __('Email *','woocommerce');
应该使用过滤器woocommerce_checkout_fields
...但它没有起作用。 - Louis