1. Knowledge Base
  2. WooCommerce Protected Categories
  3. Advanced Usage

Setting passwords via the WooCommerce REST API

At the present time, the WooCommerce Protected Categories plugin does not provide native support for creating passwords via the REST API. However, you can hook into the category creation endpoint as follows:

add_action( 'woocommerce_rest_insert_product_cat', 'wc_rest_insert_protected_category', 10, 3 );
function wc_rest_insert_protected_category( $term, $request, $creating ) {
    if ( $creating ) {
        $password = '1234abcd';
        add_woocommerce_term_meta( $term->term_id, 'password', esc_attr( $password ) );
    }
}

Still need help?

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

Related Articles