• I have a custom role (customer-service) for staff processing orders and managing users details, which has the user-edit permission enabled. However they cannot see everything on this page like the admin can.

    I need them to be able to edit the users woocommerce addresses (billing and shipping addresses) but with no additional access to other woocommerce areas. I can’t find a way to enable this using the plugin or searching through forums. Everything else is there except for these fields.

    Could you tell me how this is possible please?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    By default WooCommerce shows billing/shipping address fields at user profile for the user with ‘manage_woocommerce’ capability only. But WC developers allows to change this logic via custom filter ‘woocommerce_current_user_can_edit_customer_meta_fields’.

    
    public function add_customer_meta_fields( $user ) {
    if ( ! apply_filters( 'woocommerce_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_woocommerce' ), $user->ID ) ) {
    	return;
    }
    

    Use code below as a sample to show billing/shipping address fields to a user with selected role. Replace ‘subadmin’ with a role of your choice.

    
    add_filter( 'woocommerce_current_user_can_edit_customer_meta_fields', 'edit_wc_customer_meta_fields_cap', 10, 1 );
    
    function edit_wc_customer_meta_fields_cap( $can_manage_woocommerce ) {
        
        if ( $can_manage_woocommerce ) {
            return $can_manage_woocommerce;
        }
        
        $user = wp_get_current_user();
        if ( in_array( 'subadmin', $user->roles ) ) {
            return true;
        }
    
        return false;
    }
    
    
    • This reply was modified 5 years, 3 months ago by Vladimir Garagulya. Reason: code sample was added
    Thread Starter msdsl

    (@msdsl)

    Thank you very much Vladimir, that works perfectly ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Woocommerce Address Fields’ is closed to new replies.