Woocommerce: remove all form labels at once

余生长醉 提交于 2020-06-12 08:19:54

问题


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?

Thanks!


EDIT:

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.


回答1:


You can remove any $field->property with unset.
Good reading and references can be found here: Customizing checkout fields using actions and filters

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;
}
  • Online example: http://codepad.org/drvBYYS8
  • Related with good advise in acepted answer: WooCommerce Change Form Labels and Remove Fields



回答2:


You can do this with css by adding the below, other than this I don't know of a way to remove all the labels at once.

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


来源:https://stackoverflow.com/questions/25442289/woocommerce-remove-all-form-labels-at-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!