Back to Community

How to Restrict WooCommerce Products and Content by User Role with the Members Plugin

Content

Many WordPress site owners use the Members – Membership & User Role Editor Plugin to manage user capabilities. A common goal is to restrict access to specific content, such as WooCommerce products, based on a user's role. However, users often discover that the plugin's core functionality has limitations in this area. This guide explains what the plugin can and cannot do out-of-the-box and provides common solutions for achieving product and content restrictions.

The Core Limitation: Content vs. Full Page Protection

The primary function of the Members plugin's content permissions feature is to protect the main content body of a post, page, or custom post type. This is the content typically entered into the WordPress editor.

When it comes to WooCommerce or other complex plugins, this approach has a significant limitation. While it will hide the product description, it often will not hide other elements such as:

  • The product title
  • The product price
  • The "Add to Cart" button
  • The product image gallery
  • The product in shop archives or category pages

This happens because these elements are usually pulled from post meta data or are part of the theme's template structure, which the plugin's basic content restriction does not cover. As confirmed in multiple support threads, the Members plugin team states that fully protecting a product on the frontend is not a native feature.

Common Solutions for Restricting Access

1. Using Code Snippets for Redirects

A widely suggested solution is to use custom PHP code to redirect users without the required role away from protected content entirely. This method is more comprehensive as it protects the entire page or post.

Example: Redirect from a Product Page

add_action( 'template_redirect', function() {
  $user = wp_get_current_user();
  if ( is_singular( 'product' ) && is_user_logged_in() && in_array( 'restricted-role', (array) $user->roles ) ) {
    wp_redirect( home_url( '/restricted-access-page/' ) );
    exit;
  }
} );

This code checks if a logged-in user with the 'restricted-role' is trying to view a single product page. If so, it redirects them to a custom "Access Denied" page.

2. Hiding Products from Shop and Archives

To prevent products from even appearing in shop listings for certain roles, you can use a filter on the product query. This snippet, often shared by the plugin's support, hooks into WooCommerce's visibility check.

add_filter( 'woocommerce_product_is_visible', 'members_maybe_remove_product_from_query', 95, 2 );
function members_maybe_remove_product_from_query( $is_visible, $product_id ) {
    // Your logic to check user role and product category goes here
    // Return false if the product should be hidden
    return $is_visible;
}

You would need to add custom logic inside this function to determine which products should be hidden based on the current user's role.

3. Investigating Third-Party Plugin Capabilities

As seen in the sample threads, a frequent recommendation is to check if the plugin you are trying to integrate with (e.g., WooCommerce, Gravity Forms, an LMS) provides its own capabilities for the specific task. The Members plugin excels at managing these capabilities if they exist.

For example:

  • WooCommerce: Check if it provides a specific capability for managing stock, which you could then assign to a custom role.
  • Gravity Forms: Contact their support to ask if they provide a capability that controls front-end form visibility, not just backend form management.

If these capabilities exist, you can use the Members plugin's role editor to grant or deny them to specific user roles.

4. Considering Specialized Plugins

For complex WooCommerce role-based restrictions—such as making products visible only to certain roles, or allowing a role to only see orders for specific products—a dedicated extension might be necessary. The Members plugin team has sometimes suggested plugins like Product Visibility by User Role for WooCommerce for more advanced and native WooCommerce integration.

Conclusion and Best Practices

The Members plugin is a powerful tool for managing roles and capabilities, but it is not a complete front-end content restriction suite for all scenarios. Its strength lies in controlling backend access and basic content protection.

For advanced front-end restrictions, especially with e-commerce or learning management systems, be prepared to:

  1. Use custom code for redirects and query modifications.
  2. Research the capabilities provided by your other plugins.
  3. Evaluate if a specialized plugin is a better fit for your specific use case.

Always test any code snippets in a staging environment before deploying them to a live site.

Related Support Threads Support