0

I can’t Assign Roles on WordPress Multisite (Except Customer) in Woocommerce.

File Path: \wp-content\plugins\woocommerce\includes\wc-user-functions.php
Function Name: wc_modify_editable_roles

Code before Changes:

function wc_modify_editable_roles( $roles ) {   if ( ! current_user_can( 'administrator' ) ) {      unset( $roles['administrator'] );   }

    if ( current_user_can( 'shop_manager' ) ) {             
        $shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );    
        return array_intersect_key( $roles, array_flip( $shop_manager_editable_roles ) );    
    }

    return $roles; 
} 
add_filter( 'editable_roles', 'wc_modify_editable_roles' );

Code After Changes:

function wc_modify_editable_roles( $roles ) {
    if ( ! current_user_can( 'administrator' ) ) {
        unset( $roles['administrator'] );

        if ( current_user_can( 'shop_manager' ) ) {
            $shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
            return array_intersect_key( $roles, array_flip( $shop_manager_editable_roles ) );
        }
    }

    return $roles;
} 
add_filter( 'editable_roles', 'wc_modify_editable_roles' );

Also check this for more info - https://wordpress.org/support/topic/cant-assign-roles-on-wordpress-multisite-except-customer/

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • What is the question? – LoicTheAztec Oct 25 '18 at 09:50
  • If it's a question and an answer, then you should add the 2nd code part in an answer. "Fixed" is not needed or allowed in question titles. You just need to answer to your own question here and make a real question, with explanations as nobody can really understand it actually. – LoicTheAztec Oct 25 '18 at 10:08

1 Answers1

0

This is the correct code which will resolve the issue if you faced this above issue;

function wc_modify_editable_roles( $roles ) {
if ( ! current_user_can( 'administrator' ) ) {
    unset( $roles['administrator'] );

    if ( current_user_can( 'shop_manager' ) ) {
        $shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
        return array_intersect_key( $roles, array_flip( $shop_manager_editable_roles ) );
    }
}

return $roles; } add_filter( 'editable_roles', 'wc_modify_editable_roles' );