Woocommerce:一次删除所有表单标签 [英] Woocommerce: remove all form labels at once
问题描述
我正在使用WooCommerce建立网店.
I'm using WooCommerce to build a webshop.
表单的确定格式是没有标签,只有占位符.我一直在像这样删除标签:
The determined format for forms is that there's no labels, only placeholders. I've been removing the labels like so:
<?php
// WooCommerce Checkout Fields Hook
add_filter( 'woocommerce_checkout_fields' , 'custom_wc_checkout_fields' );
// Change the format of fields with type, label, placeholder, class, required, clear, label_class, options
function custom_wc_checkout_fields( $fields ) {
//BILLING
$fields['billing']['billing_first_name']['label'] = false;
return $fields;
}
?>
但是,由于我不希望在任何地方贴标签,所以我想知道是否有一种方法可以一次删除所有标签.而不是逐一检查它们.有人有主意吗?
But since I want no labels anywhere, I was wondering if there's a way to remove all of them at once. Instead of going through them all individually. Does anybody have an idea?
谢谢!
我意识到仅通过添加一些css(不显示任何内容)就可以实现此目的,但是由于这不是一个很干净的解决方案,因此我想知道是否还有其他方法可以实现此目的.
I realize this is possible by just adding some css(display none), but since this is not a very clean solution, I was wondering if there is some other way to accomplish this.
推荐答案
您可以使用unset
删除任何$field->property
.
在这里可以找到良好的阅读和参考:使用操作和过滤器自定义结帐字段
You can remove any $field->property
with unset
.
Good reading and references can be found here: Customizing checkout fields using actions and filters
现在,对于如何在全局范围内执行操作的问题,您可以使用loop
,例如:
Now, for your question in how to do it globally, you can use a loop
, something like:
// WooCommerce Checkout Fields Hook
add_filter('woocommerce_checkout_fields','custom_wc_checkout_fields_no_label');
// Our hooked in function - $fields is passed via the filter!
// Action: remove label from $fields
function custom_wc_checkout_fields_no_label($fields) {
// loop by category
foreach ($fields as $category => $value) {
// loop by fields
foreach ($fields[$category] as $field => $property) {
// remove label property
unset($fields[$category][$field]['label']);
}
}
return $fields;
}
- 在线示例: http://codepad.org/drvBYYS8
- 与接受建议的答案中的良好建议相关: WooCommerce更改表单标签并删除字段
- Online example: http://codepad.org/drvBYYS8
- Related with good advise in acepted answer: WooCommerce Change Form Labels and Remove Fields
这篇关于Woocommerce:一次删除所有表单标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!