1. Casa
  2. Knowledge Base
  3. WooCommerce Prezzi all'ingrosso Premium
  4. Backend
  5. Come Consentire ai Responsabili del Negozio di Modificare gli Utenti in WooCommerce

Come Consentire ai Responsabili del Negozio di Modificare gli Utenti in WooCommerce

Starting from WooCommerce version 3.4.6, a security fix was introduced that restricts Shop Managers from editing other users, except those with the Customer role.

This means that by default, Shop Managers cannot edit users who have wholesale roles created by plugins such as WooCommerce Wholesale Prices or Wholesale Prices Premium.

Suppose you’d like your Shop Managers to be able to edit (and promote) users with wholesale roles. In that case, you can easily enable this functionality by adding the following code to your site.

How to Enable Shop Managers to Edit Wholesale Users

Add the following snippet to your theme’s functions.php file, your child theme, or a custom plugin.

/**
 * Allow Shop Managers to edit and promote wholesale users.
 */
function wws_add_shop_manager_user_editing_capability() {
    $shop_manager = get_role('shop_manager');

    if ( ! $shop_manager ) {
        return;
    }

    // Only add capabilities if they don't already exist
    if ( ! $shop_manager->has_cap('edit_users') ) {
        // Core WP + WooCommerce capabilities
        $shop_manager->add_cap('list_users');
        $shop_manager->add_cap('edit_users');
        $shop_manager->add_cap('create_users');
        $shop_manager->add_cap('promote_users');
        $shop_manager->add_cap('add_users');
    }
}
add_action('init', 'wws_add_shop_manager_user_editing_capability');

/**
 * Allow Shop Managers to edit wholesale roles.
 */
function wws_allow_shop_manager_wholesale_roles( $roles ) {
    $wholesale_roles = array(
        'wholesale_customer',
        'wholesale_gold',
    );

    foreach ( $wholesale_roles as $role ) {
        // Only add if the role exists in WordPress
        if ( get_role( $role ) && ! in_array( $role, $roles, true ) ) {
            $roles[] = $role;
        }
    }

    return $roles;
}
add_filter('woocommerce_shop_manager_editable_roles', 'wws_allow_shop_manager_wholesale_roles', 20);

/**
 * Some versions of Wholesale Prices Premium use their own editable roles filter.
 * Note: This filter may not exist in current versions - keeping for backward compatibility.
 */
function wws_allow_shop_manager_wholesale_roles_wholesale_suite( $roles ) {
    $wholesale_roles = array(
        'wholesale_customer',
        'wholesale_gold',
    );

    foreach ( $wholesale_roles as $role ) {
        // Only add if the role exists in WordPress
        if ( get_role( $role ) && ! in_array( $role, $roles, true ) ) {
            $roles[] = $role;
        }
    }

    return $roles;
}
add_filter('wwp_shop_manager_editable_roles', 'wws_allow_shop_manager_wholesale_roles_wholesale_suite', 20);


What This Snippet Does

  • Restores user editing capabilities for the Shop Manager role, allowing them to view, edit, and promote users.
  • Adds support for wholesale roles, such as wholesale_customer or other wholesalle custom roles.
  • Maintains backward compatibility with older versions of the Wholesale Prices Premium plugin that use a different filter.

You can add or remove wholesale roles from the $wholesale_roles array as needed to match your site’s configuration.

Domande frequenti

How do I let Shop Managers edit wholesale users in WooCommerce?
Add the provided PHP snippet to your child theme’s functions.php file or a custom plugin. This restores editing access that was restricted since WooCommerce 3.4.6, allowing Shop Managers to open and manage wholesale user profiles directly.

Does this fix work with WooCommerce Wholesale Prices Premium too?
Yes. The code supports both the free and premium versions of WooCommerce Wholesale Prices, as well as older Wholesale Suite releases. It includes a backward-compatible function to handle legacy setups automatically.

Which wholesale roles can Shop Managers access with this code?
By default, the filter applies to the following roles:

  • wholesale_customer
  • wholesale_gold

You can expand access by adding more role slugs to the $wholesale_roles array in the file—no additional tools needed.

Can Shop Managers also create new wholesale accounts using this?
Yes. The snippet grants the following capabilities:

  • list_users
  • create_users
  • add_users
  • promote_users
  • edit_users

This allows Shop Managers to register new accounts and manage existing ones without requiring full administrator privileges.

Why can’t my Shop Manager still see wholesale profiles after applying the fix?
If the issue persists:

  • Ensure the PHP snippet is added to an active child theme’s functions.php file or a dedicated plugin.
  • Confirm that WooCommerce Wholesale Prices is installed and activated, as the solution depends on its configuration.

Serve Aiuto?

Se hai una domanda o riscontri problemi, siamo qui per aiutarti.

Questo articolo è stato utile?

Articoli Correlati

Completa il tuo acquisto