1. Home
  2. Knowledge Base
  3. WooCommerce Protected Categories
  4. Developer Documentation

Database information

WooCommerce Protected Categories lets you restrict access to specific categories either through password protection, or to specific users or user roles.

This article explains where this information is stored in the WordPress My SQL database. For example, you might need to know this in order to use the WordPress REST API to programatically assign specific users to categories, instead of doing it manually.

Database locations

The user, role and password information is stored to the wp_termmeta database table using the following keys: 'users', 'user_roles' and 'password'.

Each of these is stored as an array. For user protected categories, we store the user IDs in this array.

Example

Here's an example of assigning a new user (with user ID 10) to a category with ID 123:

// the ID of the product category.
$term_id = 123; 
// get the current list of user IDs. 
$user_ids = get_term_meta( $term_id, 'users', true ); 
// add the user ID to the category. 
$user_ids[] = 10; 
// update the category.
update_term_meta( $term_id, 'users', $user_ids );

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.