Claudio Sanches on "[Plugin: WooCommerce] How to remove address form from User Profile?"

ساخت وبلاگ

Jason Wong
Member
Posted 2 days ago #

I like to know how do I remove the Customer Billing and Shipping Address forms that were added into User Profile </wp-admin/profile.php>. I wish to do so for Administrator and Editor roles only, and not to hack any core files. Will appreciate some help to achieve the above in the active theme's functions.php

Thank you in advance.

https://wordpress.org/plugins/woocommerce/

This should already be hidden for any user who can 'manage_woocommerce' no?

Jason Wong
Member
Posted 2 days ago #

I'm uncertain because it's my first time using WooCommerce. Could you help me out, please?

Admin users have manage_woocommerce

If you edit the profile of an admin user, you won't see those fields.

Jason Wong
Member
Posted 2 days ago #

How do I implement this in functions.php ...?

Jason Wong
Member
Posted 2 days ago #

Apparently, the Editor role has the Customer Billing and Shipping Address forms added into User Profile </wp-admin/profile.php>. Isn't that only made available to Administrator, as you've mentioned above?

Jason Wong
Member
Posted 2 days ago #

It's alright. I just found this forum thread -- https://wordpress.org/support/topic/remove-billing-and-shipping-address-from-user-profile?replies=3 -- which I'll extend to only remove the address fields from Administrator and Editor roles.

Jason Wong
Member
Posted 20 hours ago #

I've tried the following code in functions.php, but sadly it didn't work. Both shipping and billing addresses disappeared for all roles, when I only want that to happen to current users who're Editor level and above.

/* WooCommerce: Hide Addresses from User Profile
=============================================================== */
function wc_hide_customer_meta_fields( $fields ) { // For Editor level and above if ( current_user_can( 'manage_categories' ) ) { retu ''; } retu $fields;
}
add_filter( 'woocommerce_customer_meta_fields', 'wc_hide_customer_meta_fields' );

I'm unsure what or where I went wrong. Please advise. Thank you.

Jason Wong
Member
Posted 6 hours ago #

By the way, I forgot to mention that 'manage_woocommerce' isn't working as I could still see the address fields in the administrator's profile. Something is definitely broken with the latest version ...

@eljkmw yes, because administrators have manage_woocommerce capability.

You can use the follow code to allow only Shop Managers to edit it:

function wc_hide_customer_meta_fields( $fields ) { // Exclude from authors and editors if ( ! current_user_can( 'manage_woocommerce' ) ) { retu ''; } // Show only for shop managers if ( ! current_user_can( 'activate_plugins' ) ) { retu $fields; } retu '';
}
add_filter( 'woocommerce_customer_meta_fields', 'wc_hide_customer_meta_fields' );

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 221 تاريخ : سه شنبه 15 تير 1395 ساعت: 12:07