Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Woocommerce:一次删除所有表单标签_Php_Wordpress_Forms_Woocommerce_Labels - Fatal编程技术网

Php Woocommerce:一次删除所有表单标签

Php Woocommerce:一次删除所有表单标签,php,wordpress,forms,woocommerce,labels,Php,Wordpress,Forms,Woocommerce,Labels,我正在用WooCommerce建立一个网店 表单的确定格式是没有标签,只有占位符。我一直在移除标签,如下所示: <?php // WooCommerce Checkout Fields Hook add_filter( 'woocommerce_checkout_fields' , 'custom_wc_checkout_fields' ); // Change the format of fields with type, label, placeholder, class, req

我正在用WooCommerce建立一个网店

表单的确定格式是没有标签,只有占位符。我一直在移除标签,如下所示:

<?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;
}
?>

但由于我不想在任何地方贴标签,我想知道是否有一种方法可以一次删除所有标签。而不是一个一个地看。有人有主意吗

谢谢


编辑:


我意识到只需添加一些css(无显示)就可以实现这一点,但由于这不是一个非常干净的解决方案,我想知道是否有其他方法可以实现这一点。

您可以通过添加以下css来实现这一点,除此之外,我不知道如何一次删除所有标签

.woocommerce form.checkout label 
{
    display: none;
}

您可以使用
取消设置
删除任何
$field->property

良好的阅读和参考可以在这里找到:

现在,对于如何全局执行的问题,您可以使用
循环
,类似于:

// 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;
}
  • 在线示例:
  • 在接受的回答中与良好建议相关:

谢谢您的回答。我已经想到了这一点,但我想知道是否还有其他方法,因为这不是一个非常干净的解决方案。我可能错了,但我认为要么显示:无,要么列出每个字段。我以前需要自己隐藏标签,但找不到简单的方法这比取消设置标签好,因为如果必填字段未填充,取消设置将隐藏字段字符串。如果必填字段未填充,取消设置标签将隐藏字段字符串。