1. Home
  2. Knowledge Base
  3. WooCommerce Password Protected Categories
  4. Advanced Usage
  5. Setting passwords via the WooCommerce REST API

Setting passwords via the WooCommerce REST API

At the present time, the 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 ) );
    }
}

Was this article helpful?

Related Articles