Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide WooCommerce billing and shipping fields in WordPress user profile

I can't find an easy way to hide some WooCommerce billing and shipping fields that are visible in the user profile in the backend of WordPress.

For instance I want to hide billing_address_2 and shipping_address_2 in the WordPress user profile. Is there a good way to do that with a code snippet? I tried hiding the sixt row in css with the code below, but I can't get that to work either.

#fieldset-billing.form-table tr:nth-child(6) {
     display: none;
}

How can I hide WooCommerce billing and shipping fields in WordPress user profile?

like image 793
Sjors Avatar asked Oct 24 '25 18:10

Sjors


2 Answers

The billing and shipping fields displayed in user profile screen are filtered through the hook woocommerce_customer_meta_fields.

To remove shipping fields, you can write:

add_filter( 'woocommerce_customer_meta_fields', 'xbs_remove_shipping_fields' );
function xbs_remove_shipping_fields( $show_fields ) {
    unset( $show_fields['shipping'] );
    return $show_fields;
}

To remove all fields, you can return an empty array.

like image 172
xavier bs Avatar answered Oct 26 '25 07:10

xavier bs


You can add it in the functions.php file and just unset them so they don't get registered.

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

function custom_override_checkout_fields( $fields ) {
     unset($fields['order']['billing_address_2']);     
     unset($fields['order']['shipping_address_2']);

     return $fields;
}

Remove from Account page:

function custom_remove_checkout_fields($fields) {
    unset($fields['order']['billing_address_2']);     
    unset($fields['order']['shipping_address_2']);
    return $fields;
}

add_filter( 'woocommerce_default_address_fields', 'custom_remove_checkout_fields' );

If it shows up in another place you can just add another hook but call

add_filter( 'woocommerce_billing_fields', 'new_function_name' );

Other hooks they have available you can see in the file class-wc-countries.php

for more information and other options you can visit: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

like image 37
ethikz Avatar answered Oct 26 '25 06:10

ethikz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!