【发布时间】:2018-03-01 18:49:30
【问题描述】:
我正在尝试在我的 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;
}
但它不起作用。
【问题讨论】:
-
您好,我有一个关于您的问题的有效测试答案,请尝试一下。应该感谢一些反馈。谢谢
-
嗨@LoicTheAztec 很好的答案,谢谢。现在,如何自定义登录字段中的占位符?
$fields['account']['account_username']['placeholder'] = __( 'Email*', 'woocommerce' );应该使用过滤器woocommerce_checkout_fields...但它没有。 -
其实问题已经发在这里了:stackoverflow.com/questions/57340779/…你能在那里给我们答案吗?
-
@Louis 您的回答无法在我的帐户登录表单上使用...我已经回答...您可以查看它,如果您喜欢/想要,您可以为答案投票。
标签: php wordpress woocommerce checkout woocommerce-checkout-fields